setting.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <!-- 用户信息 -->
  2. <template>
  3. <s-layout title="用户信息" class="set-userinfo-wrap">
  4. <uni-forms
  5. :model="state.model"
  6. :rules="state.rules"
  7. labelPosition="left"
  8. border
  9. class="form-box"
  10. >
  11. <view class="bg-white">
  12. <uni-list :border="false" class="ss-p-y-40">
  13. <uni-list-chat
  14. clickable
  15. :avatar-circle="true"
  16. :title="state.model?.nickname"
  17. :avatar="state.model?.avatar"
  18. note="个性签名"
  19. @tap="sheep.$router.go('/pages/user/info')"
  20. >
  21. <view class="chat-custom-right">
  22. <text
  23. class="_icon-forward"
  24. style="color: #bbbbbb; font-size: 32rpx"
  25. ></text>
  26. </view>
  27. </uni-list-chat>
  28. <uni-list-item
  29. clickable
  30. @tap="sheep.$router.go('/pages/user/address/list')"
  31. title="实体收货地址管理"
  32. showArrow
  33. :border="false"
  34. />
  35. <uni-list-item
  36. clickable
  37. @tap="sheep.$router.go('/pages/user/dummyAddress/list')"
  38. title="虚拟收货地址管理"
  39. showArrow
  40. :border="false"
  41. />
  42. <uni-list-item
  43. title="支付宝账号"
  44. showArrow
  45. clickable
  46. :border="false"
  47. @tap="onChangeAlipayAccount">
  48. <template v-slot:body>
  49. <p style="width: 100%"
  50. >支付宝账号&nbsp;&nbsp;{{alipayAccount?alipayAccount:'未绑定'}}
  51. </p>
  52. </template>
  53. </uni-list-item>
  54. <uni-list-item
  55. title="银行卡"
  56. showArrow
  57. clickable
  58. :border="false"
  59. @tap="onChangeBankAccount">
  60. <template v-slot:body>
  61. <p style="width: 100%"
  62. >银行卡&nbsp;&nbsp;{{bankAccount?bankAccount:'未绑定'}}
  63. </p>
  64. </template>
  65. </uni-list-item>
  66. <!-- <uni-list-item
  67. clickable
  68. @tap="sheep.$router.go('/pages/user/invoice/list')"
  69. title="发票抬头管理"
  70. showArrow
  71. :border="false"
  72. /> -->
  73. <uni-list-item
  74. :clickable="!userInfo.mobile"
  75. @tap="sheep.$router.go('/pages/user/address/list')"
  76. title="实名认证"
  77. showArrow
  78. :border="false"
  79. >
  80. <template v-slot:body>
  81. <p style="width: 100%"
  82. >实名认证&nbsp;&nbsp; 未认证
  83. </p>
  84. </template>
  85. </uni-list-item>
  86. <uni-list-item
  87. v-if="userWallet.isPtSystemUser"
  88. :clickable="true"
  89. @tap="goBackEnd('pt')"
  90. title="进入平台"
  91. showArrow
  92. :border="false"
  93. >
  94. <template v-slot:body>
  95. <p style="width: 100%"
  96. >进入平台
  97. </p>
  98. </template>
  99. </uni-list-item>
  100. <uni-list-item
  101. v-if="userWallet.isShSystemUser"
  102. :clickable="true"
  103. @tap="goBackEnd('sh')"
  104. title="进入商家后台"
  105. showArrow
  106. :border="false"
  107. >
  108. <template v-slot:body>
  109. <p style="width: 100%"
  110. >进入商家后台
  111. </p>
  112. </template>
  113. </uni-list-item>
  114. <uni-list-item
  115. title="我的二维码"
  116. clickable
  117. @tap="sheep.$router.go('/pages/user/qrcode-share')"
  118. :border="false"
  119. >
  120. <template v-slot:body>
  121. <p style="width: 100%; display: flex; align-items: center">
  122. 我的二维码&nbsp;&nbsp;&nbsp;&nbsp;
  123. <su-image
  124. class="content-img"
  125. style="border: 1px solid #f4f4f4"
  126. :current="0"
  127. :src="state.model?.avatar"
  128. :height="100"
  129. :width="100"
  130. :radius="0"
  131. mode="scaleToFill"
  132. />
  133. </p>
  134. </template>
  135. </uni-list-item>
  136. </uni-list>
  137. </view>
  138. </uni-forms>
  139. <su-fixed bottom placeholder>
  140. <view class="ss-p-x-20 ss-p-b-40">
  141. <button class="loginout-btn ss-reset-button" @tap="onLogout" v-if="isLogin">
  142. 退出登录
  143. </button>
  144. </view>
  145. </su-fixed>
  146. <!-- <su-fixed bottom placeholder bg="none">
  147. <view class="footer-box ss-p-20">
  148. <button class="ss-rest-button logout-btn ui-Shadow-Main" @tap="onSubmit">保存</button>
  149. </view>
  150. </su-fixed> -->
  151. </s-layout>
  152. </template>
  153. <script setup>
  154. import { computed, reactive, onBeforeMount } from 'vue';
  155. import sheep from '@/sheep';
  156. import { clone } from 'lodash';
  157. const isLogin = computed(() => sheep.$store('user').isLogin);
  158. import { showAuthModal, showShareModal } from '@/sheep/hooks/useModal';
  159. import FileApi from '@/sheep/api/infra/file';
  160. import UserApi from '@/sheep/api/member/user';
  161. import AuthUtil from '@/sheep/api/member/auth';
  162. import {
  163. onLoad
  164. } from '@dcloudio/uni-app';
  165. const userInfo = computed(() => sheep.$store('user').userInfo);
  166. const userWallet = computed(() => sheep.$store('user').userWallet);
  167. const alipayAccount = computed(() => {
  168. let account = userInfo.value.alipayAccount;
  169. if (!account) {
  170. return false;
  171. }
  172. // 手机号脱敏
  173. if (/^\d{11}$/.test(account)) { // 检查是否是11位数字的手机号
  174. return `${account.substring(0, 3)}****${account.substring(7)}`;
  175. } else if (/^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/.test(account)) {
  176. const atIndex = account.indexOf('@');
  177. // 邮箱用户名长度小于等于3位时,不脱敏
  178. if (atIndex <= 3) {
  179. return account;
  180. }
  181. const username = account.substring(0, Math.ceil(atIndex / 2)); // 取邮箱用户名的一半
  182. const domain = account.substring(atIndex); // 邮箱域名部分
  183. return `${username}***${domain}`;
  184. }
  185. })
  186. const bankAccount = computed(() => {
  187. let account = userInfo.value.bankAccount;
  188. if (!account) {
  189. return false;
  190. }
  191. if (account.length === 8) {
  192. return account.substring(0, 2) + '********' + account.substr(-2);
  193. } else {
  194. return account.substring(0, 4) + '******' + account.substr(-4);
  195. }
  196. })
  197. // 修改支付宝账号
  198. const onChangeAlipayAccount = () => {
  199. showAuthModal('alipayAccount');
  200. };
  201. // 修改银行卡号
  202. const onChangeBankAccount = () => {
  203. showAuthModal('bankAccount');
  204. };
  205. const state = reactive({
  206. model: {}, // 个人信息
  207. rules: {},
  208. thirdInfo: {}, // 社交用户的信息
  209. });
  210. const placeholderStyle = 'color:#BBBBBB;font-size:28rpx;line-height:normal';
  211. // 绑定第三方账号
  212. async function bindThirdOauth() {
  213. let result = await sheep.$platform.useProvider('wechat').bind();
  214. if (result) {
  215. await getUserInfo();
  216. }
  217. }
  218. // 解绑第三方账号
  219. function unBindThirdOauth() {
  220. uni.showModal({
  221. title: '解绑提醒',
  222. content: '解绑后您将无法通过微信登录此账号',
  223. cancelText: '再想想',
  224. confirmText: '确定',
  225. success: async function (res) {
  226. if (!res.confirm) {
  227. return;
  228. }
  229. const result = await sheep.$platform
  230. .useProvider('wechat')
  231. .unbind(state.thirdInfo.openid);
  232. if (result) {
  233. await getUserInfo();
  234. }
  235. },
  236. });
  237. }
  238. // 保存信息
  239. async function onSubmit() {
  240. const { code } = await UserApi.updateUser({
  241. avatar: state.model.avatar,
  242. nickname: state.model.nickname,
  243. sex: state.model.sex,
  244. });
  245. if (code === 0) {
  246. await getUserInfo();
  247. }
  248. }
  249. // 获得用户信息
  250. const getUserInfo = async () => {
  251. // 个人信息
  252. const userInfo = await sheep.$store('user').getInfo();
  253. state.model = clone(userInfo);
  254. // 获得社交用户的信息
  255. if (sheep.$platform.name !== 'H5') {
  256. const result = await sheep.$platform.useProvider('wechat').getInfo();
  257. state.thirdInfo = result || {};
  258. }
  259. };
  260. // 退出账号
  261. function onLogout() {
  262. uni.showModal({
  263. title: '提示',
  264. content: '确认退出账号?',
  265. success: async function(res) {
  266. if (!res.confirm) {
  267. return;
  268. }
  269. const {
  270. code
  271. } = await AuthUtil.logout();
  272. if (code !== 0) {
  273. return;
  274. }
  275. sheep.$store('user').logout();
  276. uni.removeStorageSync('linkId');
  277. sheep.$router.go('/pages/index/user');
  278. },
  279. });
  280. }
  281. // 跳到平台到商户
  282. async function goBackEnd(type){
  283. const {
  284. code,
  285. data
  286. } = await AuthUtil.getConsumerRedirectUrl();
  287. if(code === 0){
  288. window.location.href = data;
  289. }
  290. }
  291. onBeforeMount(() => {
  292. getUserInfo();
  293. });
  294. onLoad(()=>{
  295. uni.$on('alipayAccountChangeComplete', getUserInfo);
  296. uni.$on('bankAccountChangeComplete', getUserInfo);
  297. })
  298. </script>
  299. <style lang="scss" scoped>
  300. .loginout-btn {
  301. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  302. color:#fff;
  303. width: 100%;
  304. height: 80rpx;
  305. border-radius: 40rpx;
  306. font-size: 30rpx;
  307. }
  308. :deep() {
  309. .uni-file-picker {
  310. border-radius: 50%;
  311. }
  312. .uni-list-chat__content-extra {
  313. display: flex;
  314. justify-content: center;
  315. }
  316. .uni-file-picker__container {
  317. margin: -14rpx -12rpx;
  318. }
  319. .file-picker__progress {
  320. height: 0 !important;
  321. }
  322. .uni-list-item__content-title {
  323. font-size: 32rpx !important;
  324. color: #333333 !important;
  325. line-height: normal !important;
  326. }
  327. .uni-icons {
  328. font-size: 40rpx !important;
  329. }
  330. .is-disabled {
  331. color: #333333;
  332. }
  333. }
  334. :deep(.disabled) {
  335. opacity: 1;
  336. }
  337. .uni-list-item {
  338. min-height: 100rpx;
  339. }
  340. .gender-name {
  341. font-size: 28rpx;
  342. font-weight: 500;
  343. line-height: normal;
  344. color: #333333;
  345. }
  346. .title-box {
  347. font-size: 28rpx;
  348. font-weight: 500;
  349. color: #666666;
  350. line-height: 100rpx;
  351. }
  352. .logout-btn {
  353. width: 710rpx;
  354. height: 80rpx;
  355. background: linear-gradient(90deg, #132b85, #193bb6);
  356. border-radius: 40rpx;
  357. font-size: 30rpx;
  358. font-weight: 500;
  359. color: $white;
  360. }
  361. .radio-dark {
  362. filter: grayscale(100%);
  363. filter: gray;
  364. opacity: 0.4;
  365. }
  366. .content-img {
  367. border-radius: 50%;
  368. }
  369. .header-box-content {
  370. position: relative;
  371. width: 160rpx;
  372. height: 160rpx;
  373. overflow: hidden;
  374. border-radius: 50%;
  375. }
  376. .avatar-action {
  377. position: absolute;
  378. left: 50%;
  379. transform: translateX(-50%);
  380. bottom: 0;
  381. z-index: 1;
  382. width: 160rpx;
  383. height: 46rpx;
  384. background: rgba(#000000, 0.3);
  385. .avatar-action-btn {
  386. width: 160rpx;
  387. height: 46rpx;
  388. font-weight: 500;
  389. font-size: 24rpx;
  390. color: #ffffff;
  391. }
  392. }
  393. // 绑定项
  394. .account-list {
  395. background-color: $white;
  396. height: 100rpx;
  397. padding: 0 20rpx;
  398. .list-img {
  399. width: 40rpx;
  400. height: 40rpx;
  401. margin-right: 10rpx;
  402. }
  403. .list-name {
  404. font-size: 28rpx;
  405. color: #333333;
  406. }
  407. .info {
  408. .avatar {
  409. width: 38rpx;
  410. height: 38rpx;
  411. border-radius: 50%;
  412. overflow: hidden;
  413. }
  414. .name {
  415. font-size: 28rpx;
  416. font-weight: 400;
  417. color: $dark-9;
  418. }
  419. }
  420. .bind-box {
  421. width: 100rpx;
  422. height: 50rpx;
  423. line-height: normal;
  424. display: flex;
  425. justify-content: center;
  426. align-items: center;
  427. font-size: 24rpx;
  428. .bind-btn {
  429. width: 100%;
  430. height: 100%;
  431. border-radius: 25rpx;
  432. background: #f4f4f4;
  433. color: #999999;
  434. }
  435. .relieve-btn {
  436. width: 100%;
  437. height: 100%;
  438. border-radius: 25rpx;
  439. background: var(--ui-BG-Main-opacity-1);
  440. color: var(--ui-BG-Main);
  441. }
  442. }
  443. }
  444. .list-border {
  445. font-size: 28rpx;
  446. font-weight: 400;
  447. color: #333333;
  448. border-bottom: 2rpx solid #eeeeee;
  449. }
  450. image {
  451. width: 100%;
  452. height: 100%;
  453. }
  454. </style>