setting.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. <!-- 用户设置 -->
  2. <template>
  3. <s-layout :title="$t('setting.set')" 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="">
  13. <uni-list-chat
  14. clickable
  15. :avatar-circle="true"
  16. :title="state.model?.nickname"
  17. :avatar="state.model?.avatar"
  18. :note="$t('setting.signature')"
  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="$t('setting.physical_address_management')"
  32. showArrow
  33. :border="false"
  34. />
  35. <uni-list-item
  36. clickable
  37. @tap="sheep.$router.go('/pages/user/dummyAddress/list')"
  38. :title="$t('setting.virtual_address_management')"
  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. >{{$t('setting.alipay_account')}}&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. >{{$t('setting.bank_card')}}&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. >{{$t('setting.enter_platform')}}
  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. >{{$t('setting.enter_merchant_backend')}}
  111. </p>
  112. </template>
  113. </uni-list-item>
  114. <uni-list-item
  115. v-if="isBetaUser()"
  116. :clickable="true"
  117. @tap="changeLanguage()"
  118. title="切换语言"
  119. showArrow
  120. :border="false"
  121. >
  122. <template v-slot:body>
  123. <p style="width: 100%"
  124. >{{currentLang === 'en' ? 'Switch to Chinese': '切换为英文'}}
  125. </p>
  126. </template>
  127. </uni-list-item>
  128. <uni-list-item
  129. title="我的二维码"
  130. clickable
  131. @tap="sheep.$router.go('/pages/user/qrcode-share')"
  132. :border="false"
  133. >
  134. <template v-slot:body>
  135. <p style="width: 100%; display: flex; align-items: center">
  136. {{$t('setting.enter_merchant_backend')}} &nbsp;&nbsp;&nbsp;&nbsp;
  137. <su-image
  138. class="content-img"
  139. style="border: 1px solid #f4f4f4"
  140. :current="0"
  141. :src="state.model?.avatar"
  142. :height="100"
  143. :width="100"
  144. :radius="0"
  145. mode="scaleToFill"
  146. />
  147. </p>
  148. </template>
  149. </uni-list-item>
  150. </uni-list>
  151. </view>
  152. </uni-forms>
  153. <!-- 当前社交平台的绑定关系,只处理 wechat 微信场景 -->
  154. <view v-if="sheep.$platform.name !== 'H5'">
  155. <view class="title-box ss-p-l-30">{{$t('setting.third_party_account_binding')}}</view>
  156. <view class="account-list ss-flex ss-row-between">
  157. <view v-if="'WechatOfficialAccount' === sheep.$platform.name" class="ss-flex ss-col-center">
  158. <image class="list-img" :src="sheep.$url.static('/static/images/WechatOfficialAccount.png')" />
  159. <text class="list-name">{{$t('setting.wechat_public_account')}}</text>
  160. </view>
  161. <view v-if="'WechatMiniProgram' === sheep.$platform.name" class="ss-flex ss-col-center">
  162. <image class="list-img" :src="sheep.$url.static('/static/images/WechatMiniProgram.png')" />
  163. <text class="list-name">{{$t('setting.wechat_mini_program')}}</text>
  164. </view>
  165. <view v-if="'App' === sheep.$platform.name" class="ss-flex ss-col-center">
  166. <image class="list-img" :src="sheep.$url.static('/static/images/wechat.png')" />
  167. <text class="list-name">{{$t('setting.wechat_open_platform')}}</text>
  168. </view>
  169. <view class="ss-flex ss-col-center">
  170. <view class="info ss-flex ss-col-center" v-if="state.thirdInfo">
  171. <image class="avatar ss-m-r-20" :src="sheep.$url.cdn(state.thirdInfo.avatar)" />
  172. <text class="name">{{ state.thirdInfo.nickname }}</text>
  173. </view>
  174. <view class="bind-box ss-m-l-20">
  175. <button v-if="state.thirdInfo.openid" class="ss-reset-button relieve-btn"
  176. @tap="unBindThirdOauth">
  177. {{ $t('setting.unbind') }}
  178. </button>
  179. <button v-else class="ss-reset-button bind-btn" @tap="bindThirdOauth">{{$t('setting.bind')}}</button>
  180. </view>
  181. </view>
  182. </view>
  183. </view>
  184. <su-fixed bottom placeholder>
  185. <view class="ss-p-x-20 ss-p-b-40">
  186. <button class="loginout-btn ss-reset-button" @tap="onLogout" v-if="isLogin">
  187. {{$t('user.log_out')}}
  188. </button>
  189. </view>
  190. </su-fixed>
  191. <!-- <su-fixed bottom placeholder bg="none">
  192. <view class="footer-box ss-p-20">
  193. <button class="ss-rest-button logout-btn ui-Shadow-Main" @tap="onSubmit">保存</button>
  194. </view>
  195. </su-fixed> -->
  196. </s-layout>
  197. </template>
  198. <script setup>
  199. import { computed, reactive, onBeforeMount } from 'vue';
  200. import sheep from '@/sheep';
  201. import { clone } from 'lodash';
  202. const isLogin = computed(() => sheep.$store('user').isLogin);
  203. import { showAuthModal, showShareModal } from '@/sheep/hooks/useModal';
  204. import FileApi from '@/sheep/api/infra/file';
  205. import UserApi from '@/sheep/api/member/user';
  206. import AuthUtil from '@/sheep/api/member/auth';
  207. import { isBetaUser } from '@/sheep/hooks/useApp.js'
  208. import {
  209. onLoad
  210. } from '@dcloudio/uni-app';
  211. import { setLanguage } from '@/locale'
  212. import { useI18n } from 'vue-i18n';
  213. const { t } = useI18n();
  214. const userInfo = computed(() => sheep.$store('user').userInfo);
  215. const userWallet = computed(() => sheep.$store('user').userWallet);
  216. const alipayAccount = computed(() => {
  217. let account = userInfo.value.alipayAccount;
  218. if (!account) {
  219. return false;
  220. }
  221. // 手机号脱敏
  222. if (/^\d{11}$/.test(account)) { // 检查是否是11位数字的手机号
  223. return `${account.substring(0, 3)}****${account.substring(7)}`;
  224. } else if (/^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/.test(account)) {
  225. const atIndex = account.indexOf('@');
  226. // 邮箱用户名长度小于等于3位时,不脱敏
  227. if (atIndex <= 3) {
  228. return account;
  229. }
  230. const username = account.substring(0, Math.ceil(atIndex / 2)); // 取邮箱用户名的一半
  231. const domain = account.substring(atIndex); // 邮箱域名部分
  232. return `${username}***${domain}`;
  233. }
  234. })
  235. const bankAccount = computed(() => {
  236. let account = userInfo.value.bankAccount;
  237. if (!account) {
  238. return false;
  239. }
  240. if (account.length === 8) {
  241. return account.substring(0, 2) + '********' + account.substr(-2);
  242. } else {
  243. return account.substring(0, 4) + '******' + account.substr(-4);
  244. }
  245. })
  246. // 修改支付宝账号
  247. const onChangeAlipayAccount = () => {
  248. showAuthModal('alipayAccount');
  249. };
  250. // 修改银行卡号
  251. const onChangeBankAccount = () => {
  252. showAuthModal('bankAccount');
  253. };
  254. const state = reactive({
  255. model: {}, // 个人信息
  256. rules: {},
  257. thirdInfo: {}, // 社交用户的信息
  258. });
  259. const placeholderStyle = 'color:#BBBBBB;font-size:28rpx;line-height:normal';
  260. // 绑定第三方账号
  261. async function bindThirdOauth() {
  262. let result = await sheep.$platform.useProvider('wechat').bind();
  263. if (result) {
  264. await getUserInfo();
  265. }
  266. }
  267. // 解绑第三方账号
  268. function unBindThirdOauth() {
  269. uni.showModal({
  270. title: t('user.unbind_reminder'),
  271. content:t('rules.unbind_warning'),
  272. cancelText: t('common.cancel'),
  273. confirmText: t('common.confirm'),
  274. success: async function(res) {
  275. if (!res.confirm) {
  276. return;
  277. }
  278. const result = await sheep.$platform.useProvider('wechat').unbind(state.thirdInfo.openid);
  279. if (result) {
  280. await getUserInfo();
  281. }
  282. },
  283. });
  284. }
  285. // 保存信息
  286. async function onSubmit() {
  287. const { code } = await UserApi.updateUser({
  288. avatar: state.model.avatar,
  289. nickname: state.model.nickname,
  290. sex: state.model.sex,
  291. });
  292. if (code === 0) {
  293. await getUserInfo();
  294. }
  295. }
  296. // 获得用户信息
  297. const getUserInfo = async () => {
  298. // 个人信息
  299. const userInfo = await sheep.$store('user').getInfo();
  300. state.model = clone(userInfo);
  301. // 获得社交用户的信息
  302. if (sheep.$platform.name !== 'H5') {
  303. const result = await sheep.$platform.useProvider('wechat').getInfo();
  304. state.thirdInfo = result || {};
  305. }
  306. };
  307. // 退出账号
  308. function onLogout() {
  309. uni.showModal({
  310. title: t('setting.prompt'),
  311. content: t('setting.confirm_logout'),
  312. cancelText: t('common.cancel'),
  313. confirmText: t('common.confirm'),
  314. success: async function(res) {
  315. if (!res.confirm) {
  316. return;
  317. }
  318. const {
  319. code
  320. } = await AuthUtil.logout();
  321. if (code !== 0) {
  322. return;
  323. }
  324. sheep.$store('user').logout();
  325. uni.removeStorageSync('linkId');
  326. sheep.$router.go('/pages/index/user');
  327. },
  328. });
  329. }
  330. // 跳到平台到商户
  331. async function goBackEnd(type){
  332. const {
  333. code,
  334. data
  335. } = await AuthUtil.getConsumerRedirectUrl();
  336. if(code === 0){
  337. window.location.href = data;
  338. }
  339. }
  340. const currentLang = computed(() => {
  341. return uni.getStorageSync('userLanguage');
  342. });
  343. const changeLanguage = async () => {
  344. // setLanguage()
  345. console.log(currentLang.value)
  346. if(currentLang.value === 'en'){
  347. await UserApi.updateUser({language: 'zh-Hans'});
  348. setLanguage('zh-Hans');
  349. }else{
  350. await UserApi.updateUser({language: 'en'});
  351. setLanguage('en');
  352. }
  353. }
  354. onBeforeMount(() => {
  355. getUserInfo();
  356. });
  357. onLoad(()=>{
  358. uni.$on('alipayAccountChangeComplete', getUserInfo);
  359. uni.$on('bankAccountChangeComplete', getUserInfo);
  360. })
  361. </script>
  362. <style lang="scss" scoped>
  363. .loginout-btn {
  364. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  365. color:#fff;
  366. width: 100%;
  367. height: 80rpx;
  368. border-radius: 40rpx;
  369. font-size: 30rpx;
  370. }
  371. :deep() {
  372. .uni-file-picker {
  373. border-radius: 50%;
  374. }
  375. .uni-list-chat__content-extra {
  376. display: flex;
  377. justify-content: center;
  378. }
  379. .uni-file-picker__container {
  380. margin: -14rpx -12rpx;
  381. }
  382. .file-picker__progress {
  383. height: 0 !important;
  384. }
  385. .uni-list-item__content-title {
  386. font-size: 32rpx !important;
  387. color: #333333 !important;
  388. line-height: normal !important;
  389. }
  390. .uni-icons {
  391. font-size: 40rpx !important;
  392. }
  393. .is-disabled {
  394. color: #333333;
  395. }
  396. }
  397. :deep(.disabled) {
  398. opacity: 1;
  399. }
  400. .uni-list-item {
  401. min-height: 100rpx;
  402. }
  403. .gender-name {
  404. font-size: 28rpx;
  405. font-weight: 500;
  406. line-height: normal;
  407. color: #333333;
  408. }
  409. .title-box {
  410. font-size: 28rpx;
  411. font-weight: 500;
  412. color: #666666;
  413. line-height: 60rpx;
  414. }
  415. .logout-btn {
  416. width: 710rpx;
  417. height: 80rpx;
  418. background: linear-gradient(90deg, #132b85, #193bb6);
  419. border-radius: 40rpx;
  420. font-size: 30rpx;
  421. font-weight: 500;
  422. color: $white;
  423. }
  424. .radio-dark {
  425. filter: grayscale(100%);
  426. filter: gray;
  427. opacity: 0.4;
  428. }
  429. .content-img {
  430. border-radius: 50%;
  431. }
  432. .header-box-content {
  433. position: relative;
  434. width: 160rpx;
  435. height: 160rpx;
  436. overflow: hidden;
  437. border-radius: 50%;
  438. }
  439. .avatar-action {
  440. position: absolute;
  441. left: 50%;
  442. transform: translateX(-50%);
  443. bottom: 0;
  444. z-index: 1;
  445. width: 160rpx;
  446. height: 46rpx;
  447. background: rgba(#000000, 0.3);
  448. .avatar-action-btn {
  449. width: 160rpx;
  450. height: 46rpx;
  451. font-weight: 500;
  452. font-size: 24rpx;
  453. color: #ffffff;
  454. }
  455. }
  456. // 绑定项
  457. .account-list {
  458. background-color: $white;
  459. height: 100rpx;
  460. padding: 0 20rpx;
  461. .list-img {
  462. width: 40rpx;
  463. height: 40rpx;
  464. margin-right: 10rpx;
  465. }
  466. .list-name {
  467. font-size: 28rpx;
  468. color: #333333;
  469. }
  470. .info {
  471. .avatar {
  472. width: 38rpx;
  473. height: 38rpx;
  474. border-radius: 50%;
  475. overflow: hidden;
  476. }
  477. .name {
  478. font-size: 28rpx;
  479. font-weight: 400;
  480. color: $dark-9;
  481. }
  482. }
  483. .bind-box {
  484. width: 100rpx;
  485. height: 50rpx;
  486. line-height: normal;
  487. display: flex;
  488. justify-content: center;
  489. align-items: center;
  490. font-size: 24rpx;
  491. .bind-btn {
  492. width: 100%;
  493. height: 100%;
  494. border-radius: 25rpx;
  495. background: #f4f4f4;
  496. color: #999999;
  497. }
  498. .relieve-btn {
  499. width: 100%;
  500. height: 100%;
  501. border-radius: 25rpx;
  502. background: var(--ui-BG-Main-opacity-1);
  503. color: var(--ui-BG-Main);
  504. }
  505. }
  506. }
  507. .list-border {
  508. font-size: 28rpx;
  509. font-weight: 400;
  510. color: #333333;
  511. border-bottom: 2rpx solid #eeeeee;
  512. }
  513. image {
  514. width: 100%;
  515. height: 100%;
  516. }
  517. </style>