index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. <template>
  2. <view style=" padding: 30rpx;">
  3. <view class="w_login">
  4. <view class="circle">
  5. </view>
  6. <view class="info1">
  7. 中意购
  8. </view>
  9. <view class="info2">
  10. 为您提供优质服务,中意够需要获取以下信息
  11. 您的公开信息 (昵称、头像)
  12. </view>
  13. </view>
  14. <view class="tool_list">
  15. <u-cell-group>
  16. <u-cell isLink>
  17. <view slot="title" class="u-slot-title">
  18. <text class="u-cell-text">用户协议</text>
  19. </view>
  20. </u-cell>
  21. <u-cell isLink>
  22. <view slot="title" class="u-slot-title">
  23. <text class="u-cell-text">隐私协议</text>
  24. </view>
  25. </u-cell>
  26. </u-cell-group>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import {
  32. getUserInfo,
  33. userEdit,
  34. getLogout
  35. } from '@/api/user.js';
  36. import {
  37. switchH5Login
  38. } from '@/api/api.js';
  39. import {
  40. toLogin
  41. } from '@/libs/login.js';
  42. import {
  43. mapGetters
  44. } from "vuex";
  45. import dayjs from "@/plugin/dayjs/dayjs.min.js";
  46. // #ifdef MP
  47. import authorize from '@/components/Authorize';
  48. // #endif
  49. import colors from '@/mixins/color.js';
  50. export default {
  51. components: {
  52. // #ifdef APP-PLUS
  53. appUpdate,
  54. // #endif
  55. // #ifdef MP
  56. authorize
  57. // #endif
  58. },
  59. mixins: [colors],
  60. data () {
  61. return {
  62. };
  63. },
  64. computed: mapGetters(['isLogin']),
  65. watch: {
  66. isLogin: {
  67. handler: function (newV, oldV) {
  68. if (newV) {
  69. this.getUserInfo();
  70. }
  71. },
  72. deep: true
  73. }
  74. },
  75. onLoad () {
  76. if (this.isLogin) {
  77. this.getUserInfo();
  78. // #ifdef APP-PLUS
  79. this.formatSize()
  80. // 获取版本号
  81. plus.runtime.getProperty(plus.runtime.appid, (inf) => {
  82. console.log(inf.version)
  83. this.version = inf.version;
  84. });
  85. // #endif
  86. this.setLang();
  87. } else {
  88. toLogin();
  89. }
  90. },
  91. methods: {
  92. isNew () {
  93. this.$util.Tips({
  94. title: this.$t(`当前为最新版本`)
  95. });
  96. },
  97. setLang () {
  98. this.array.map((item, i) => {
  99. if (this.$i18n.locale == item.value) {
  100. this.setIndex = i
  101. }
  102. })
  103. },
  104. bindPickerChange (e, item) {
  105. this.setIndex = e.detail.value
  106. this.$i18n.locale = this.array[this.setIndex].value;
  107. uni.setStorageSync('locale', this.array[this.setIndex].value);
  108. },
  109. updateApp () {
  110. this.$refs.appUpdate.update(); //调用子组件 检查更新
  111. },
  112. formatSize () {
  113. let that = this;
  114. plus.cache.calculate(function (size) {
  115. let sizeCache = parseInt(size);
  116. if (sizeCache == 0) {
  117. that.fileSizeString = "0B";
  118. } else if (sizeCache < 1024) {
  119. that.fileSizeString = sizeCache + "B";
  120. } else if (sizeCache < 1048576) {
  121. that.fileSizeString = (sizeCache / 1024).toFixed(2) + "KB";
  122. } else if (sizeCache < 1073741824) {
  123. that.fileSizeString = (sizeCache / 1048576).toFixed(2) + "MB";
  124. } else {
  125. that.fileSizeString = (sizeCache / 1073741824).toFixed(2) + "GB";
  126. }
  127. });
  128. },
  129. initData () {
  130. uni.showModal({
  131. title: this.$t(`清除缓存`),
  132. content: this.$t(`确定清楚本地缓存数据吗`),
  133. success: (res) => {
  134. if (res.confirm) {
  135. this.clearCache()
  136. this.formatSize()
  137. } else if (res.cancel) {
  138. return that.$util.Tips({
  139. title: that.$t(`取消`)
  140. });
  141. }
  142. }
  143. });
  144. },
  145. clearCache () {
  146. let that = this;
  147. let os = plus.os.name;
  148. if (os == 'Android') {
  149. let main = plus.android.runtimeMainActivity();
  150. let sdRoot = main.getCacheDir();
  151. let files = plus.android.invoke(sdRoot, "listFiles");
  152. let len = files.length;
  153. for (let i = 0; i < len; i++) {
  154. let filePath = '' + files[i]; // 没有找到合适的方法获取路径,这样写可以转成文件路径
  155. plus.io.resolveLocalFileSystemURL(filePath, function (entry) {
  156. if (entry.isDirectory) {
  157. entry.removeRecursively(function (entry) { //递归删除其下的所有文件及子目录
  158. uni.showToast({
  159. title: that.$t(`缓存清理完成`),
  160. duration: 2000
  161. });
  162. that.formatSize(); // 重新计算缓存
  163. }, function (e) {
  164. console.log(e.message)
  165. });
  166. } else {
  167. entry.remove();
  168. }
  169. }, function (e) { });
  170. }
  171. } else { // ios暂时未找到清理缓存的方法,以下是官方提供的方法,但是无效,会报错
  172. plus.cache.clear(function () {
  173. uni.showToast({
  174. title: that.$t(`缓存清理完成`),
  175. duration: 2000
  176. });
  177. that.formatSize();
  178. });
  179. }
  180. },
  181. /**
  182. * 授权回调
  183. */
  184. onLoadFun: function () {
  185. this.getUserInfo();
  186. },
  187. // 授权关闭
  188. authColse: function (e) {
  189. this.isShowAuth = e
  190. },
  191. /**
  192. * 小程序设置
  193. */
  194. Setting: function () {
  195. uni.openSetting({
  196. success: function (res) { }
  197. });
  198. },
  199. switchAccounts: function (index) {
  200. let userInfo = this.switchUserInfo[index],
  201. that = this;
  202. that.userIndex = index;
  203. if (that.switchUserInfo.length <= 1) return true;
  204. if (userInfo === undefined) return that.$util.Tips({
  205. title: that.$t(`切换的账号不存在`)
  206. });
  207. if (userInfo.user_type === 'h5') {
  208. uni.showLoading({
  209. title: that.$t(`正在切换中`)
  210. });
  211. switchH5Login().then(res => {
  212. uni.hideLoading();
  213. that.$store.commit("LOGIN", {
  214. 'token': res.data.token,
  215. 'time': this.$Cache.strTotime(res.data.expires_time) - this.$Cache.time()
  216. });
  217. that.getUserInfo();
  218. }).catch(err => {
  219. uni.hideLoading();
  220. return that.$util.Tips({
  221. title: err
  222. });
  223. })
  224. } else {
  225. that.$store.commit("LOGOUT");
  226. uni.showLoading({
  227. title: that.$t(`正在切换中`)
  228. });
  229. toLogin();
  230. }
  231. },
  232. /**
  233. * 退出登录
  234. *
  235. */
  236. outLogin: function () {
  237. let that = this;
  238. if (that.loginType == 'h5') {
  239. uni.showModal({
  240. title: that.$t(`提示`),
  241. content: that.$t(`确认退出登录`),
  242. success: function (res) {
  243. if (res.confirm) {
  244. getLogout()
  245. .then(res => {
  246. // uni.clearStorage()
  247. that.$store.commit("LOGOUT");
  248. uni.reLaunch({
  249. url: '/pages/index/index'
  250. })
  251. })
  252. .catch(err => { });
  253. } else if (res.cancel) { }
  254. }
  255. });
  256. }
  257. },
  258. /**
  259. * 获取用户详情
  260. */
  261. getUserInfo: function () {
  262. let that = this;
  263. getUserInfo().then(res => {
  264. that.$set(that, 'userInfo', res.data);
  265. let switchUserInfo = res.data.switchUserInfo || [];
  266. for (let i = 0; i < switchUserInfo.length; i++) {
  267. if (switchUserInfo[i].uid == that.userInfo.uid) that.userIndex = i;
  268. // 切割h5用户;user_type状态:h5、routine(小程序)、wechat(公众号);注:只有h5未注册手机号时,h5才可和小程序或是公众号数据想通;
  269. //#ifdef H5
  270. if (
  271. !that.$wechat.isWeixin() &&
  272. switchUserInfo[i].user_type != "h5" &&
  273. switchUserInfo[i].phone === ""
  274. )
  275. switchUserInfo.splice(i, 1);
  276. //#endif
  277. }
  278. that.$set(that, "switchUserInfo", switchUserInfo);
  279. });
  280. },
  281. /**
  282. * 上传文件
  283. *
  284. */
  285. uploadpic: function () {
  286. let that = this;
  287. this.canvasStatus = true
  288. that.$util.uploadImageChange('upload/image', (res) => {
  289. let userInfo = that.switchUserInfo[that.userIndex];
  290. if (userInfo !== undefined) {
  291. that.userInfo.avatar = res.data.url;
  292. }
  293. that.switchUserInfo[that.userIndex] = userInfo;
  294. that.$set(that, 'switchUserInfo', that.switchUserInfo);
  295. this.canvasStatus = false
  296. }, (res) => {
  297. this.canvasStatus = false
  298. }, (res) => {
  299. this.canvasWidth = res.w
  300. this.canvasHeight = res.h
  301. });
  302. },
  303. /**
  304. * 提交修改
  305. */
  306. formSubmit: function (e) {
  307. let that = this,
  308. value = e.detail.value,
  309. userInfo = that.switchUserInfo[that.userIndex];
  310. if (!value.nickname) return that.$util.Tips({
  311. title: that.$t(`请输入姓名`)
  312. });
  313. value.avatar = this.userInfo.avatar;
  314. userEdit(value).then(res => {
  315. return that.$util.Tips({
  316. title: res.msg,
  317. icon: 'success'
  318. }, {
  319. tab: 3,
  320. url: 1
  321. });
  322. }).catch(msg => {
  323. return that.$util.Tips({
  324. title: msg || that.$t(`保存失败`)
  325. }, {
  326. tab: 3,
  327. url: 1
  328. });
  329. });
  330. }
  331. }
  332. }
  333. </script>
  334. <style scoped lang="scss">
  335. .cartcolor {
  336. color: var(--view-theme);
  337. border: 1px solid var(--view-theme);
  338. }
  339. .personal-data .wrapper {
  340. margin: 10rpx 0;
  341. background-color: #fff;
  342. padding: 36rpx 30rpx 13rpx 30rpx;
  343. }
  344. .personal-data .wrapper .title {
  345. margin-bottom: 30rpx;
  346. font-size: 32rpx;
  347. color: #282828;
  348. }
  349. .group-buying-data {
  350. position: relative;
  351. width: 100%;
  352. height: 200rpx;
  353. padding: 40rpx;
  354. margin: 0 auto;
  355. background-image: url('http://www.gzzzyd.com/groupon/regiment/提货管理@2x.png');
  356. background-size: 100% auto;
  357. background-color: var(--view-theme);
  358. .group-title {
  359. font-size: 32rpx;
  360. font-weight: 500;
  361. color: #B22338;
  362. line-height: 44rpx;
  363. height: 44rpx;
  364. }
  365. .group-content {
  366. display: flex;
  367. .group-content-l {
  368. text-align: center;
  369. flex: 1;
  370. border-color: #333333;
  371. border-right: 1px solid dashed;
  372. }
  373. .group-content-r {
  374. text-align: center;
  375. flex: 1
  376. }
  377. .content-num {
  378. margin-top: 20rpx;
  379. height: 48rpx;
  380. font-size: 40rpx;
  381. font-weight: bold;
  382. color: #B22338;
  383. line-height: 48rpx;
  384. }
  385. .content-info {
  386. margin-top: 20rpx;
  387. text-align: center;
  388. width: 100%;
  389. height: 36rpx;
  390. font-size: 24rpx;
  391. font-weight: 400;
  392. color: #CF7986;
  393. line-height: 36rpx;
  394. }
  395. }
  396. }
  397. .tool_list,
  398. .footer {
  399. background: #fff;
  400. border-radius: 16rpx;
  401. margin-top: 20rpx;
  402. }
  403. .footer {
  404. height: 100rpx;
  405. button {
  406. height: 100%;
  407. font-size: 28rpx;
  408. font-weight: 400;
  409. color: #999999;
  410. line-height: 100rpx;
  411. }
  412. }
  413. /deep/ .tool_list .u-line,
  414. .my_order .u-line {
  415. display: none !important;
  416. }
  417. .u-slot-title {
  418. line-height: 60rpx;
  419. font-size: 28rpx;
  420. font-weight: 400;
  421. color: #333333;
  422. text {
  423. vertical-align: text-bottom;
  424. }
  425. image {
  426. margin-right: 20rpx;
  427. transform: translateY(10rpx);
  428. width: 40rpx;
  429. height: 40rpx;
  430. vertical-align: super;
  431. }
  432. }
  433. .w_login {
  434. padding: 30rpx;
  435. .circle {
  436. border-radius: 50%;
  437. width: 106rpx;
  438. height: 106rpx;
  439. background: rgb(238, 238, 238);
  440. margin: auto;
  441. }
  442. .info1 {
  443. text-align: center;
  444. font-size: 48rpx;
  445. font-weight: 600;
  446. color: #333333;
  447. line-height: 66rpx;
  448. margin-bottom: 30rpx;
  449. }
  450. .info2 {
  451. text-align: center;
  452. font-size: 28rpx;
  453. font-weight: 400;
  454. color: #999999;
  455. line-height: 44rpx;
  456. margin-bottom: 120rpx;
  457. }
  458. .now {
  459. width: 100%;
  460. height: 96rpx;
  461. background: #B42A3E;
  462. border-radius: 8rpx;
  463. font-size: 32rpx;
  464. font-weight: 400;
  465. color: #FFFFFF;
  466. line-height: 96rpx;
  467. margin-bottom: 20rpx;
  468. }
  469. .not_now {
  470. width: 100%;
  471. height: 96rpx;
  472. background: #F5F5F5;
  473. border-radius: 8rpx;
  474. font-size: 32rpx;
  475. font-weight: 400;
  476. color: #999999;
  477. line-height: 96rpx;
  478. }
  479. }
  480. </style>