index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. <template>
  2. <view :style="viewColor">
  3. <form>
  4. <view class='personal-data'>
  5. <view class="wrapper" v-if="switchUserInfo.length>0">
  6. <view class="title">管理我的账号</view>
  7. <view class="wrapList" >
  8. <view class="item acea-row row-between-wrapper" :class="item.uid === userInfo.uid ? 'on' : ''"
  9. :style="{ 'background-image': `url(${item.uid == userInfo.uid ? domain+'/static/diy/currentAcc'+keyColor+'.png' : '' })` }"
  10. v-for="(item,index) in switchUserInfo"
  11. :key="index">
  12. <view class="picTxt acea-row row-between-wrapper">
  13. <block v-if='item.uid === userInfo.uid'>
  14. <view class="pictrue" v-if="!mp_is_new" @click="uploadpic">
  15. <image :src="item.avatar || '/static/images/f.png'"></image>
  16. <view v-if="open_update_info != 0" class="radius" ><span class="iconfont iconfonta icon-jilu-xuanzhong"></span></view>
  17. </view>
  18. <button v-if="mp_is_new && open_update_info != 0" class="avatar-box pictrue" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  19. <image :src="item.avatar || '/static/images/f.png'"></image>
  20. <view class="radius" ><span class="iconfont iconfonta icon-jilu-xuanzhong"></span></view>
  21. </button>
  22. <button v-else-if="mp_is_new && open_update_info == 0" class="avatar-box">
  23. <image :src="item.avatar || '/static/images/f.png'"></image>
  24. </button>
  25. </block>
  26. <view class="pictrue" v-else>
  27. <image :src="item.avatar || '/static/images/f.png'"></image>
  28. <view class="radius" v-if="open_update_info != 0"><span class="iconfont iconfonta icon-jilu-xuanzhong"></span></view>
  29. </view>
  30. <view class="text">
  31. <view class="name line1">{{ item.nickname }}</view>
  32. </view>
  33. </view>
  34. <view class="currentBnt acea-row row-center-wrapper t-color" v-if='item.uid === userInfo.uid'>
  35. 当前账号
  36. </view>
  37. <view class="bnt t-color acea-row row-center-wrapper" @click='switchAccounts(item,index)' v-else>
  38. 使用账号
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="list" v-else>
  44. <view class='item acea-row row-between-wrapper' >
  45. <view>头像</view>
  46. <view class="pictrue" v-if="!mp_is_new" @click="uploadpic">
  47. <image class="avatar" :src="userInfo.avatar || '/static/images/f.png'"></image>
  48. </view>
  49. <button v-else class="avatar-box" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  50. <image :src="userInfo.avatar || '/static/images/f.png'"></image>
  51. </button>
  52. </view>
  53. </view>
  54. <view class='list' style="margin-top: 1rpx;">
  55. <view class='item acea-row row-between-wrapper'>
  56. <view>昵称</view>
  57. <view class='input acea-row row-between-wrapper' @click="changeInput">
  58. <input type='text' name='nickname' :value='userInfo.nickname' class='id' disabled>
  59. <text v-if="open_update_info != 0" class='iconfont icon-you'></text>
  60. <text v-else class='iconfont icon-suozi'></text>
  61. </view>
  62. </view>
  63. <view class='item acea-row row-between-wrapper'>
  64. <view>ID号</view>
  65. <view class='input acea-row row-between-wrapper'>
  66. <input type='text' :value='userInfo.uid' disabled='true' class='id'></input>
  67. <text class='iconfont icon-suozi'></text>
  68. </view>
  69. </view>
  70. <view class='item acea-row row-between-wrapper'>
  71. <view>手机号码</view>
  72. <navigator url="/pages/users/user_phone/index" hover-class="none" class="input" v-if="!userInfo.phone">
  73. 点击绑定手机号<text class="iconfont icon-xiangyou"></text>
  74. </navigator>
  75. <navigator url="/pages/users/user_modify_phone/index" hover-class="none" class='input acea-row row-between-wrapper' v-else>
  76. <text class='id'>{{userInfo.phone}}</text>
  77. <text class='iconfont icon-you'></text>
  78. </navigator>
  79. </view>
  80. <view class='item acea-row row-between-wrapper'>
  81. <view>登录密码</view>
  82. <view class='input acea-row row-between-wrapper' @click="changePwd">
  83. <text class='id'>修改登录密码</text>
  84. <text class='iconfont icon-you'></text>
  85. </view>
  86. </view>
  87. <view class='item acea-row row-between-wrapper'>
  88. <view>地址管理</view>
  89. <navigator url="/pages/users/user_address_list/index" hover-class="none" class='input acea-row row-between-wrapper'>
  90. <text class='id'>立即前往</text>
  91. <text class='iconfont icon-you'></text>
  92. </navigator>
  93. </view>
  94. <view class='item acea-row row-between-wrapper'>
  95. <view>发票管理</view>
  96. <navigator url="/pages/users/user_invoice_list/index" hover-class="none" class='input acea-row row-between-wrapper'>
  97. <text class='id'>立即前往</text>
  98. <text class='iconfont icon-you'></text>
  99. </navigator>
  100. </view>
  101. <view class='item acea-row row-between-wrapper'>
  102. <view>详细信息</view>
  103. <navigator url="/pages/users/user_info_form/index" hover-class="none" class='input acea-row row-between-wrapper'>
  104. <text class='id'>立即前往</text>
  105. <text class='iconfont icon-you'></text>
  106. </navigator>
  107. </view>
  108. <view class='item acea-row row-between-wrapper'>
  109. <view>注销账号</view>
  110. <view class='input acea-row row-between-wrapper' @click="changeCancel">
  111. <text class='id'>账号注销后不能恢复</text>
  112. <text class='iconfont icon-you'></text>
  113. </view>
  114. </view>
  115. <!--#ifdef APP-PLUS-->
  116. <view class='item acea-row row-between-wrapper'>
  117. <view>当前版本</view>
  118. <view class='input acea-row row-between-wrapper'>
  119. <input type='text' :value='version' disabled='true' class='id'></input>
  120. </view>
  121. </view>
  122. <!--#endif-->
  123. </view>
  124. <!-- #ifdef H5 -->
  125. <view class="logOut acea-row row-center-wrapper" @click="outLogin" v-if="!this.$wechat.isWeixin()">退出登录</view>
  126. <!-- #endif -->
  127. <!-- #ifdef MP || APP-PLUS -->
  128. <view class="logOut acea-row row-center-wrapper" @click="outLogin">退出登录</view>
  129. <!-- #endif -->
  130. <view class="foot-bar"></view>
  131. </view>
  132. </form>
  133. </view>
  134. </template>
  135. <script>
  136. // +----------------------------------------------------------------------
  137. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  138. // +----------------------------------------------------------------------
  139. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  140. // +----------------------------------------------------------------------
  141. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  142. // +----------------------------------------------------------------------
  143. // | Author: CRMEB Team <admin@crmeb.com>
  144. // +----------------------------------------------------------------------
  145. import { getUserInfo, getLogout, userAcc, editAvatar } from '@/api/user.js';
  146. import { switchH5Login } from '@/api/api.js';
  147. import { mapGetters } from "vuex";
  148. import { configMap } from '@/utils';
  149. import dayjs from "@/plugin/dayjs/dayjs.min.js";
  150. import Cache from '@/utils/cache';
  151. import { HTTP_REQUEST_URL } from '@/config/app';
  152. import { toLogin } from '@/libs/login.js';
  153. export default {
  154. components: {},
  155. data() {
  156. return {
  157. domain: HTTP_REQUEST_URL,
  158. userInfo: {},
  159. loginType: 'h5',
  160. userIndex: 0,
  161. switchUserInfo: [],
  162. headBg: '../static/images/currentAcc',
  163. mp_is_new: this.$Cache.get('MP_VERSION_ISNEW') || false,
  164. version: ''
  165. };
  166. },
  167. computed: configMap({open_update_info: 0} ,mapGetters(['isLogin','viewColor','keyColor'])),
  168. onLoad() {
  169. if (this.isLogin) {
  170. this.getUserInfo();
  171. } else {
  172. toLogin()
  173. }
  174. //#ifdef APP-PLUS
  175. this.appVersionConfig()
  176. //#endif
  177. },
  178. methods: {
  179. toggle(type) {
  180. this.type = type
  181. // open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
  182. this.$refs.popup.open(type)
  183. },
  184. /**
  185. * 上传图片文件
  186. *
  187. */
  188. uploadpic: function() {
  189. let that = this;
  190. if(that.open_update_info == 0){
  191. return;
  192. }
  193. that.$util.uploadImageOne('upload/image', function(res) {
  194. let userInfo = that.switchUserInfo[that.userIndex];
  195. if (userInfo !== undefined) {
  196. userInfo.avatar = res.data.path;
  197. }
  198. that.switchUserInfo[that.userIndex] = userInfo;
  199. editAvatar({avatar:res.data.path}).then((res)=>{
  200. that.$util.Tips({
  201. title:res.message,
  202. })
  203. })
  204. });
  205. },
  206. // 修改昵称
  207. changeInput(){
  208. if(this.open_update_info == 0){
  209. return;
  210. }
  211. uni.navigateTo({
  212. url: '/pages/users/user_nickname/index',
  213. })
  214. },
  215. // 微信头像获取
  216. onChooseAvatar(e) {
  217. const {avatarUrl} = e.detail
  218. this.$util.uploadImgs('upload/image', avatarUrl, (res) => {
  219. this.userInfo.avatar = res.data.path
  220. editAvatar({avatar:res.data.path}).then((res)=>{
  221. that.$util.Tips({
  222. title:res.message,
  223. })
  224. })
  225. }, (err) => {
  226. console.log(err)
  227. })
  228. },
  229. // #ifdef APP-PLUS
  230. appVersionConfig() {
  231. var that = this;
  232. plus.runtime.getProperty(plus.runtime.appid, (info) => {
  233. this.version = info.version;
  234. console.log('当前版本:'+ info.version)
  235. });
  236. },
  237. //#endif
  238. switchAccounts: function(item, index) {
  239. let userInfo = this.switchUserInfo[index],
  240. that = this;
  241. that.userIndex = index;
  242. if (that.switchUserInfo.length <= 1) return true;
  243. if (userInfo === undefined) return that.$util.Tips({
  244. title: '切换的账号不存在'
  245. });
  246. uni.showLoading({
  247. title: '正在切换中'
  248. });
  249. switchH5Login({
  250. uid: item.uid
  251. }).then(({
  252. data
  253. }) => {
  254. uni.hideLoading();
  255. let newTime = Math.round(new Date() / 1000);
  256. that.$store.commit("LOGIN", {
  257. 'token': data.token,
  258. 'time': data.exp,
  259. });
  260. that.$store.commit("SETUID", data.user.uid);
  261. that.$store.commit('UPDATE_USERINFO', data.user);
  262. that.getUserInfo();
  263. }).catch(err => {
  264. uni.hideLoading();
  265. return that.$util.Tips({
  266. title: err
  267. });
  268. })
  269. },
  270. /**
  271. * 退出登录
  272. *
  273. */
  274. outLogin: function() {
  275. let that = this;
  276. if (that.loginType == 'h5') {
  277. uni.showModal({
  278. title: '提示',
  279. content: '确认退出登录?',
  280. success: function(res) {
  281. if (res.confirm) {
  282. getLogout()
  283. .then(res => {
  284. that.$store.commit("LOGOUT");
  285. uni.reLaunch({
  286. url: '/pages/index/index',
  287. });
  288. })
  289. .catch(err => {
  290. console.log(err);
  291. });
  292. } else if (res.cancel) {
  293. console.log('用户点击取消');
  294. }
  295. }
  296. });
  297. }
  298. },
  299. // 获取用户列表
  300. userAcc() {
  301. userAcc().then(res => {
  302. let that = this
  303. let switchUserInfo = res.data || [];
  304. for (let i = 0; i < switchUserInfo.length; i++) {
  305. if (switchUserInfo[i].uid == that.userInfo.uid) that.userIndex = i;
  306. // 切割h5用户;user_type状态:h5、routine(小程序)、wechat(公众号);注:只有h5未注册手机号时,h5才可和小程序或是公众号数据想通;
  307. //#ifdef H5
  308. if (
  309. !that.$wechat.isWeixin() &&
  310. switchUserInfo[i].user_type != "h5" &&
  311. switchUserInfo[i].phone === ""
  312. )
  313. switchUserInfo.splice(i, 1);
  314. //#endif
  315. }
  316. that.$set(that, "switchUserInfo", switchUserInfo);
  317. })
  318. },
  319. /**修改密码*/
  320. changePwd(){
  321. let that = this;
  322. if(that.userInfo.phone){
  323. uni.navigateTo({
  324. url: `/pages/users/user_modify_pwd/index`
  325. })
  326. }else{
  327. that.$util.Tips({
  328. title: '请先绑定手机号'
  329. });
  330. }
  331. },
  332. //注销账号
  333. changeCancel(){
  334. uni.navigateTo({
  335. url: '/pages/users/user_about/index?from='+'the_cancellation_msg'
  336. })
  337. },
  338. /**
  339. * 获取用户详情
  340. */
  341. getUserInfo: function() {
  342. let that = this;
  343. getUserInfo().then(res => {
  344. that.$set(that, 'userInfo', res.data);
  345. if(res.data.phone){
  346. that.userAcc();
  347. }
  348. });
  349. }
  350. }
  351. }
  352. </script>
  353. <style scoped lang="scss">
  354. html{
  355. -webkit-text-size-adjust:none;
  356. }
  357. .radius{
  358. background-color: white;
  359. width: 35rpx;
  360. height: 35rpx;
  361. border-radius: 50%;
  362. border: 1px solid rgb(187, 43, 5);
  363. line-height: 25rpx;
  364. text-align: center;
  365. position: absolute;
  366. right: 0;
  367. bottom: 0;
  368. }
  369. .iconfonta{
  370. border-radius: 50%;
  371. font-size: 20rpx;
  372. color: red;
  373. }
  374. .avatar {
  375. width: 120rpx;
  376. height: 120rpx;
  377. border-radius: 50%;
  378. }
  379. .btnb{
  380. border-radius: 0;
  381. height: 100rpx;
  382. line-height: 100rpx;
  383. }
  384. .btna{
  385. height: 100rpx;
  386. line-height: 100rpx;
  387. border-radius: 10rpx 10rpx 0 0;
  388. }
  389. .btnc{
  390. height: 130rpx;
  391. line-height: 130rpx;
  392. border-radius: 0;
  393. }
  394. .personal-data {
  395. padding-bottom: calc(0rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  396. padding-bottom: calc(0rpx + env(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  397. }
  398. .personal-data .wrapper {
  399. margin: 10rpx 0;
  400. background-color: #fff;
  401. padding: 36rpx 30rpx 13rpx 30rpx;
  402. }
  403. .personal-data .wrapper .title {
  404. margin-bottom: 30rpx;
  405. font-size: 32rpx;
  406. color: #282828;
  407. }
  408. .personal-data .wrapper .wrapList .item {
  409. width: 690rpx;
  410. height: 160rpx;
  411. background-color: #f8f8f8;
  412. border-radius: 20rpx;
  413. margin-bottom: 22rpx;
  414. padding: 0 30rpx;
  415. position: relative;
  416. border: 2rpx solid #f8f8f8;
  417. box-sizing: border-box;
  418. }
  419. .t-color {
  420. color: var(--view-theme);
  421. }
  422. .personal-data .wrapper .wrapList .item.on {
  423. border-color: var(--view-theme);
  424. border-radius: 20rpx;
  425. background-size: 100% 100%;
  426. background-color: var(--view-minorColor);
  427. background-repeat: no-repeat;
  428. }
  429. .personal-data .wrapper .wrapList .item .picTxt {
  430. width: 445rpx;
  431. }
  432. .personal-data .wrapper .wrapList .item .picTxt .pictrue {
  433. width: 96rpx;
  434. height: 96rpx;
  435. position: relative;
  436. }
  437. .personal-data .wrapper .wrapList .item .picTxt .pictrue image {
  438. width: 100%;
  439. height: 100%;
  440. border-radius: 50%;
  441. }
  442. .personal-data .wrapper .wrapList .item .picTxt .text {
  443. width: 325rpx;
  444. }
  445. .personal-data .wrapper .wrapList .item .picTxt .text .name {
  446. width: 100%;
  447. font-size: 30rpx;
  448. color: #282828;
  449. }
  450. .personal-data .wrapper .wrapList .item .picTxt .text .phone {
  451. font-size: 24rpx;
  452. color: #999;
  453. margin-top: 10rpx;
  454. }
  455. .personal-data .wrapper .wrapList .item .bnt {
  456. font-size: 24rpx;
  457. background-color: #fff;
  458. border-radius: 27rpx;
  459. width: 140rpx;
  460. height: 54rpx;
  461. border: 2rpx solid var(--view-theme);
  462. }
  463. .personal-data .wrapper .wrapList .item .currentBnt {
  464. position: absolute;
  465. right: 0;
  466. top: 0;
  467. font-size: 26rpx;
  468. background-color: var(--view-minorColor);
  469. width: 140rpx;
  470. height: 48rpx;
  471. border-radius: 0 20rpx 0 20rpx;
  472. }
  473. .personal-data .list {
  474. margin-top: 15rpx;
  475. background-color: #fff;
  476. }
  477. .personal-data .list .item {
  478. padding-right: 30rpx;
  479. height: 110rpx;
  480. border-bottom: 1px solid #f2f2f2;
  481. margin-left: 30rpx;
  482. font-size: 32rpx;
  483. color: #282828;
  484. }
  485. .personal-data .list .item .phone {
  486. width: 160rpx;
  487. height: 56rpx;
  488. font-size: 24rpx;
  489. color: #fff;
  490. line-height: 56rpx;
  491. border-radius: 32rpx
  492. }
  493. .personal-data .list .item .pictrue {
  494. width: 88rpx;
  495. height: 88rpx;
  496. }
  497. .personal-data .list .item .pictrue image {
  498. width: 100%;
  499. height: 100%;
  500. border-radius: 50%;
  501. }
  502. .personal-data .list .item .input {
  503. min-width: 415rpx;
  504. text-align: right;
  505. color: #868686;
  506. }
  507. .personal-data .list .item .input .id {
  508. width: 365rpx;
  509. }
  510. .personal-data .list .item .input .iconfont {
  511. font-size: 35rpx;
  512. }
  513. .personal-data .modifyBnt {
  514. font-size: 32rpx;
  515. color: #fff;
  516. width: 690rpx;
  517. height: 90rpx;
  518. border-radius: 50rpx;
  519. text-align: center;
  520. line-height: 90rpx;
  521. margin: 76rpx auto 0 auto;
  522. background: var(--view-theme);
  523. }
  524. .personal-data .logOut {
  525. font-size: 32rpx;
  526. text-align: center;
  527. width: 690rpx;
  528. height: 90rpx;
  529. border-radius: 45rpx;
  530. margin: 80rpx auto 0 auto;
  531. color: var(--view-theme);
  532. background-color: #ffffff;
  533. border: 1px solid var(--view-theme);
  534. }
  535. .avatar-box {
  536. width: 96rpx;
  537. height: 96rpx;
  538. background: transparent;
  539. image {
  540. width: 100%;
  541. height: 100%;
  542. border-radius: 50%;
  543. }
  544. }
  545. </style>