info.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <template>
  2. <s-layout title="用户信息" class="set-userinfo-wrap">
  3. <uni-forms
  4. :model="state.model"
  5. :rules="state.rules"
  6. labelPosition="left"
  7. border
  8. class="form-box"
  9. >
  10. <view class="ss-flex ss-row-center ss-col-center ss-p-t-60 ss-p-b-0 bg-white">
  11. <view class="header-box-content">
  12. <su-image
  13. class="content-img"
  14. isPreview
  15. :current="0"
  16. :src="sheep.$url.cdn(state.model.avatar)"
  17. :height="160"
  18. :width="160"
  19. :radius="80"
  20. mode="scaleToFill"
  21. ></su-image>
  22. <view class="avatar-action">
  23. <!-- #ifdef MP -->
  24. <button
  25. class="ss-reset-button avatar-action-btn"
  26. open-type="chooseAvatar"
  27. @chooseavatar="onChooseAvatar"
  28. >修改</button
  29. >
  30. <!-- #endif -->
  31. <!-- #ifndef MP -->
  32. <button class="ss-reset-button avatar-action-btn" @tap="onChangeAvatar">修改</button>
  33. <!-- #endif -->
  34. </view>
  35. </view>
  36. </view>
  37. <view class="bg-white ss-p-x-30">
  38. <!-- <uni-forms-item name="username" label="用户名" @tap="onChangeUsername" class="label-box">
  39. <uni-easyinput
  40. v-model="userInfo.username"
  41. disabled
  42. :inputBorder="false"
  43. :styles="{ disableColor: '#fff' }"
  44. placeholder="设置用户名"
  45. :clearable="false"
  46. :placeholderStyle="placeholderStyle"
  47. >
  48. <template v-slot:right>
  49. <su-radio class="ss-flex" v-if="userInfo.verification?.username" :modelValue="true" />
  50. <button v-else class="ss-reset-button">
  51. <text class="_icon-forward" style="color: #bbbbbb; font-size: 26rpx"></text>
  52. </button>
  53. </template>
  54. </uni-easyinput>
  55. </uni-forms-item> -->
  56. <uni-forms-item name="nickname" label="昵称">
  57. <uni-easyinput
  58. v-model="state.model.nickname"
  59. type="nickname"
  60. placeholder="设置昵称"
  61. :inputBorder="false"
  62. :placeholderStyle="placeholderStyle"
  63. />
  64. </uni-forms-item>
  65. <!-- <uni-forms-item name="gender" label="性别">
  66. <view class="ss-flex ss-col-center ss-h-100">
  67. <radio-group @change="onChangeGender" class="ss-flex ss-col-center">
  68. <label class="radio" v-for="item in genderRadioMap" :key="item.value">
  69. <view class="ss-flex ss-col-center ss-m-r-32">
  70. <radio
  71. :value="item.value"
  72. color="var(--ui-BG-Main)"
  73. style="transform: scale(0.8)"
  74. :checked="item.value == state.model.gender"
  75. />
  76. <view class="gender-name">{{ item.name }}</view>
  77. </view>
  78. </label>
  79. </radio-group>
  80. </view>
  81. </uni-forms-item> -->
  82. <uni-forms-item name="mobile" label="手机号" @tap="onChangeMobile">
  83. <uni-easyinput
  84. v-model="userInfo.mobile"
  85. placeholder="请绑定手机号"
  86. :inputBorder="false"
  87. disabled
  88. :styles="{ disableColor: '#fff' }"
  89. :placeholderStyle="placeholderStyle"
  90. :clearable="false"
  91. >
  92. <template v-slot:right>
  93. <view class="ss-flex ss-col-center">
  94. <su-radio v-if="userInfo.verification?.mobile" :modelValue="true" />
  95. <button v-else class="ss-reset-button ss-flex ss-col-center ss-row-center">
  96. <text class="_icon-forward" style="color: #bbbbbb; font-size: 26rpx"></text>
  97. </button>
  98. </view>
  99. </template>
  100. </uni-easyinput>
  101. </uni-forms-item>
  102. <uni-forms-item name="password" label="登录密码" @tap="onSetPassword">
  103. <uni-easyinput
  104. v-model="userInfo.password"
  105. :placeholder="userInfo.verification?.password ? '修改登录密码' : '点击设置登录密码'"
  106. :inputBorder="false"
  107. :styles="{ disableColor: '#fff' }"
  108. disabled
  109. placeholderStyle="color:#BBBBBB;font-size:28rpx;line-height:normal"
  110. :clearable="false"
  111. >
  112. <template v-slot:right>
  113. <view class="ss-flex ss-col-center">
  114. <su-radio
  115. class="ss-flex"
  116. v-if="userInfo.verification?.password"
  117. :modelValue="true"
  118. />
  119. <button v-else class="ss-reset-button ss-flex ss-col-center ss-row-center">
  120. <text class="_icon-forward" style="color: #bbbbbb; font-size: 26rpx"></text>
  121. </button>
  122. </view>
  123. </template>
  124. </uni-easyinput>
  125. </uni-forms-item>
  126. </view>
  127. <view class="bg-white ss-m-t-14">
  128. <uni-list>
  129. <uni-list-item
  130. clickable
  131. @tap="sheep.$router.go('/pages/user/address/list')"
  132. title="地址管理"
  133. showArrow
  134. :border="false"
  135. class="list-border"
  136. ></uni-list-item>
  137. <uni-list-item
  138. clickable
  139. @tap="sheep.$router.go('/pages/user/invoice/list')"
  140. title="发票管理"
  141. showArrow
  142. :border="false"
  143. class="list-border"
  144. ></uni-list-item>
  145. </uni-list>
  146. </view>
  147. </uni-forms>
  148. <view v-if="sheep.$platform.name !== 'H5'">
  149. <view class="title-box ss-p-l-30">第三方账号绑定</view>
  150. <view class="account-list ss-flex ss-row-between">
  151. <view v-if="'WechatOfficialAccount' === sheep.$platform.name" class="ss-flex ss-col-center">
  152. <image
  153. class="list-img"
  154. :src="sheep.$url.static('/static/img/shop/platform/WechatOfficialAccount.png')"
  155. />
  156. <text class="list-name">微信公众号</text>
  157. </view>
  158. <view v-if="'WechatMiniProgram' === sheep.$platform.name" class="ss-flex ss-col-center">
  159. <image
  160. class="list-img"
  161. :src="sheep.$url.static('/static/img/shop/platform/WechatMiniProgram.png')"
  162. />
  163. <text class="list-name">微信小程序</text>
  164. </view>
  165. <view v-if="'App' === sheep.$platform.name" class="ss-flex ss-col-center">
  166. <image
  167. class="list-img"
  168. :src="sheep.$url.static('/static/img/shop/platform/wechat.png')"
  169. />
  170. <text class="list-name">微信开放平台</text>
  171. </view>
  172. <view class="ss-flex ss-col-center">
  173. <view class="info ss-flex ss-col-center" v-if="state.thirdOauthInfo">
  174. <image
  175. class="avatar ss-m-r-20"
  176. :src="sheep.$url.cdn(state.thirdOauthInfo.avatar)"
  177. ></image>
  178. <text class="name">{{ state.thirdOauthInfo.nickname }}</text>
  179. </view>
  180. <view class="bind-box ss-m-l-20">
  181. <button
  182. v-if="state.thirdOauthInfo"
  183. class="ss-reset-button relieve-btn"
  184. @tap="unBindThirdOauth"
  185. >
  186. 解绑
  187. </button>
  188. <button v-else class="ss-reset-button bind-btn" @tap="bindThirdOauth">绑定</button>
  189. </view>
  190. </view>
  191. </view>
  192. </view>
  193. <su-fixed bottom placeholder bg="none">
  194. <view class="footer-box ss-p-20">
  195. <button class="ss-rest-button logout-btn ui-Shadow-Main" @tap="onSubmit">保存</button>
  196. </view>
  197. </su-fixed>
  198. </s-layout>
  199. </template>
  200. <script setup>
  201. import { computed, ref, reactive, onBeforeMount, unref } from 'vue';
  202. import { mobile, password, username } from '@/sheep/validate/form';
  203. import sheep from '@/sheep';
  204. import { clone } from 'lodash';
  205. import { showAuthModal } from '@/sheep/hooks/useModal';
  206. const state = reactive({
  207. model: {},
  208. rules: {},
  209. thirdOauthInfo: null,
  210. });
  211. const placeholderStyle = 'color:#BBBBBB;font-size:28rpx;line-height:normal';
  212. const genderRadioMap = [
  213. {
  214. name: '男',
  215. value: '1',
  216. },
  217. {
  218. name: '女',
  219. value: '2',
  220. },
  221. {
  222. name: '未知',
  223. value: '0',
  224. },
  225. ];
  226. const userInfo = computed(() => sheep.$store('user').userInfo);
  227. // 选择性别
  228. function onChangeGender(e) {
  229. state.model.gender = e.detail.value;
  230. }
  231. // 修改用户名
  232. const onChangeUsername = () => {
  233. !state.model.verification?.username && showAuthModal('changeUsername');
  234. };
  235. // 修改手机号
  236. const onChangeMobile = () => {
  237. showAuthModal('changeMobile');
  238. };
  239. function onChooseAvatar(e) {
  240. const tempUrl = e.detail.avatarUrl || '';
  241. uploadAvatar(tempUrl);
  242. }
  243. //修改头像
  244. function onChangeAvatar() {
  245. uni.chooseImage({
  246. success: async (chooseImageRes) => {
  247. const tempUrl = chooseImageRes.tempFilePaths[0];
  248. uploadAvatar(tempUrl);
  249. },
  250. });
  251. }
  252. async function uploadAvatar(tempUrl) {
  253. if (!tempUrl) return;
  254. let { path } = await sheep.$api.app.upload(tempUrl, 'ugc');
  255. state.model.avatar = path;
  256. }
  257. // 修改/设置密码
  258. function onSetPassword() {
  259. if (state.model.verification.password) {
  260. showAuthModal('changePassword');
  261. } else {
  262. showAuthModal('resetPassword');
  263. }
  264. }
  265. // 绑定第三方账号
  266. async function bindThirdOauth() {
  267. let result = await sheep.$platform.useProvider('wechat').bind();
  268. if (result) {
  269. getUserInfo();
  270. }
  271. }
  272. // 解绑第三方账号
  273. function unBindThirdOauth() {
  274. uni.showModal({
  275. title: '解绑提醒',
  276. content: '解绑后您将无法通过微信登录此账号',
  277. cancelText: '再想想',
  278. confirmText: '确定',
  279. success: async function (res) {
  280. if (res.confirm) {
  281. const result = await sheep.$platform.useProvider('wechat').unbind();
  282. if (result) {
  283. getUserInfo();
  284. }
  285. }
  286. },
  287. });
  288. }
  289. // 保存信息
  290. async function onSubmit() {
  291. // const { error, data } = await sheep.$api.user.update({
  292. // avatar: state.model.avatar,
  293. // nickname: state.model.nickname,
  294. // gender: state.model.gender,
  295. // });
  296. const { code, data } = await sheep.$api.user.update({
  297. avatar: state.model.avatar,
  298. nickname: state.model.nickname,
  299. // gender: state.model.gender,
  300. });
  301. if (code === 0) {
  302. getUserInfo();
  303. }
  304. }
  305. const getUserInfo = async () => {
  306. const userInfo = await sheep.$store('user').getInfo();
  307. state.model = clone(userInfo);
  308. if (sheep.$platform.name !== 'H5') {
  309. return;
  310. // 这个先注释,要不然小程序保存个人信息有问题,
  311. let { data, error } = await sheep.$api.user.thirdOauthInfo();
  312. if (error === 0) {
  313. state.thirdOauthInfo = data;
  314. }
  315. }
  316. };
  317. onBeforeMount(async () => {
  318. getUserInfo();
  319. });
  320. </script>
  321. <style lang="scss" scoped>
  322. :deep() {
  323. .uni-file-picker {
  324. border-radius: 50%;
  325. }
  326. .uni-file-picker__container {
  327. margin: -14rpx -12rpx;
  328. }
  329. .file-picker__progress {
  330. height: 0 !important;
  331. }
  332. .uni-list-item__content-title {
  333. font-size: 28rpx !important;
  334. color: #333333 !important;
  335. line-height: normal !important;
  336. }
  337. .uni-icons {
  338. font-size: 40rpx !important;
  339. }
  340. .is-disabled {
  341. color: #333333;
  342. }
  343. }
  344. :deep(.disabled) {
  345. opacity: 1;
  346. }
  347. .gender-name {
  348. font-size: 28rpx;
  349. font-weight: 500;
  350. line-height: normal;
  351. color: #333333;
  352. }
  353. .title-box {
  354. font-size: 28rpx;
  355. font-weight: 500;
  356. color: #666666;
  357. line-height: 100rpx;
  358. }
  359. .logout-btn {
  360. width: 710rpx;
  361. height: 80rpx;
  362. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  363. border-radius: 40rpx;
  364. font-size: 30rpx;
  365. font-weight: 500;
  366. color: $white;
  367. }
  368. .radio-dark {
  369. filter: grayscale(100%);
  370. filter: gray;
  371. opacity: 0.4;
  372. }
  373. .content-img {
  374. border-radius: 50%;
  375. }
  376. .header-box-content {
  377. position: relative;
  378. width: 160rpx;
  379. height: 160rpx;
  380. overflow: hidden;
  381. border-radius: 50%;
  382. }
  383. .avatar-action {
  384. position: absolute;
  385. left: 50%;
  386. transform: translateX(-50%);
  387. bottom: 0;
  388. z-index: 1;
  389. width: 160rpx;
  390. height: 46rpx;
  391. background: rgba(#000000, 0.3);
  392. .avatar-action-btn {
  393. width: 160rpx;
  394. height: 46rpx;
  395. font-weight: 500;
  396. font-size: 24rpx;
  397. color: #ffffff;
  398. }
  399. }
  400. // 绑定项
  401. .account-list {
  402. background-color: $white;
  403. height: 100rpx;
  404. padding: 0 20rpx;
  405. .list-img {
  406. width: 40rpx;
  407. height: 40rpx;
  408. margin-right: 10rpx;
  409. }
  410. .list-name {
  411. font-size: 28rpx;
  412. color: #333333;
  413. }
  414. .info {
  415. .avatar {
  416. width: 38rpx;
  417. height: 38rpx;
  418. border-radius: 50%;
  419. overflow: hidden;
  420. }
  421. .name {
  422. font-size: 28rpx;
  423. font-weight: 400;
  424. color: $dark-9;
  425. }
  426. }
  427. .bind-box {
  428. width: 100rpx;
  429. height: 50rpx;
  430. line-height: normal;
  431. display: flex;
  432. justify-content: center;
  433. align-items: center;
  434. font-size: 24rpx;
  435. .bind-btn {
  436. width: 100%;
  437. height: 100%;
  438. border-radius: 25rpx;
  439. background: #f4f4f4;
  440. color: #999999;
  441. }
  442. .relieve-btn {
  443. width: 100%;
  444. height: 100%;
  445. border-radius: 25rpx;
  446. background: var(--ui-BG-Main-opacity-1);
  447. color: var(--ui-BG-Main);
  448. }
  449. }
  450. }
  451. .list-border {
  452. font-size: 28rpx;
  453. font-weight: 400;
  454. color: #333333;
  455. border-bottom: 2rpx solid #eeeeee;
  456. }
  457. image {
  458. width: 100%;
  459. height: 100%;
  460. }
  461. </style>