Browse Source

增加微信号和邮箱修改

Handy_Cao 1 year ago
parent
commit
e30181ffa5

+ 10 - 0
src/packages/mobile/router/index.ts

@@ -434,6 +434,16 @@ const routes: Array<RouteRecordRaw> = [
         name: 'mine-setting',
         component: () => import('../views/mine/setting/Index.vue'),
       },
+      {
+        path: 'wechat',
+        name: 'mine-wechat',
+        component: () => import('../views/mine/wechat/Index.vue'),
+      },
+      {
+        path: 'email',
+        name: 'mine-email',
+        component: () => import('../views/mine/email/Index.vue'),
+      }
     ],
   },
   {

+ 69 - 0
src/packages/mobile/views/mine/email/Index.vue

@@ -0,0 +1,69 @@
+
+<template>
+    <app-view class="g-form">
+        <template #header>
+            <app-navbar title="邮箱" />
+        </template>
+        <Form ref="formRef" class="g-form__container" @submit="onSubmit">
+            <CellGroup inset>
+                <Field v-model="formData.email" :rules="formRules.email" name="email" label="邮箱"
+                    placeholder="必填" />
+            </CellGroup>
+        </Form>
+        <template #footer>
+            <div class="g-form__footer inset">
+                <Button round block type="danger" @click="formRef?.submit">确定</Button>
+            </div>
+        </template>
+    </app-view>
+</template>
+
+<script lang="ts" setup>
+import { shallowRef, reactive } from 'vue'
+import { Form, Field, FormInstance, CellGroup, FieldRule, Button, showFailToast } from 'vant'
+import { updateUserInfoWechatAndEmail } from '@/services/api/user'
+import { useLoginStore, useUserStore } from '@/stores'
+import { useNavigation } from '@mobile/router/navigation'
+import { fullloading } from '@/utils/vant'
+import { validateRules } from '@/constants/regex'
+import { decryptAES } from '@/services/websocket/package/crypto'
+
+// formRef
+const formRef = shallowRef<FormInstance>()
+// loginStore
+const loginStore = useLoginStore()
+// userStore
+const userStore = useUserStore()
+// router
+const { router } = useNavigation()
+
+const formData = reactive<Model.UserInfoWechatAndEmailReq>({
+    userid: loginStore.userId, // 用户ID
+    email: decryptAES(userStore.userInfo.email), //  邮箱
+})
+
+// 表单验证规则
+const formRules: { [key in keyof Model.UserInfoWechatAndEmailReq]?: FieldRule[] } = {
+    email: [{
+        validator: (val) => {
+            if (validateRules.email.validate(val)) {
+                return true
+            }
+            return validateRules.email.message
+        }
+    }],
+}
+
+const onSubmit = () => {
+    fullloading((hideLoading) => {
+        updateUserInfoWechatAndEmail({
+            data: formData
+        }).then(() => {
+            hideLoading()
+            router.back()
+        }).catch((err) => {
+            showFailToast(err)
+        })
+    })
+}
+</script>

+ 12 - 0
src/packages/mobile/views/mine/profile/Index.vue

@@ -6,10 +6,22 @@
         <CellGroup>
             <Cell title="发票信息" :to="{ name: 'mine-invoice' }" is-link />
             <Cell title="收货地址" :to="{ name: 'mine-address' }" is-link />
+            <Cell title="微信" :to="{ name: 'mine-wechat' }" :value="decryptAES(userStore.userInfo.wechat ?? '')" is-link />
+            <Cell title="邮箱" :to="{ name: 'mine-email' }" :value="decryptAES(userStore.userInfo.email ?? '')" is-link />
         </CellGroup>
     </app-view>
 </template>
 
 <script lang="ts" setup>
 import { Cell, CellGroup } from 'vant'
+import { useUserStore } from '@/stores'
+import { decryptAES } from '@/services/websocket/package/crypto'
+import { onActivated } from 'vue';
+
+// userStore
+const userStore = useUserStore()
+
+onActivated(() => {
+    userStore.getUserData()
+})
 </script>

+ 66 - 0
src/packages/mobile/views/mine/wechat/Index.vue

@@ -0,0 +1,66 @@
+
+<template>
+    <app-view class="g-form">
+        <template #header>
+            <app-navbar title="微信" />
+        </template>
+        <Form ref="formRef" class="g-form__container" @submit="onSubmit">
+            <CellGroup inset>
+                <Field v-model="formData.wechat" :rules="formRules.wechat" name="email" label="微信"
+                    placeholder="必填" />
+            </CellGroup>
+        </Form>
+        <template #footer>
+            <div class="g-form__footer inset">
+                <Button round block type="danger" @click="formRef?.submit">确定</Button>
+            </div>
+        </template>
+    </app-view>
+</template>
+
+<script lang="ts" setup>
+import { shallowRef, reactive } from 'vue'
+import { Form, Field, FormInstance, CellGroup, FieldRule, Button, showFailToast } from 'vant'
+import { updateUserInfoWechatAndEmail } from '@/services/api/user'
+import { useLoginStore, useUserStore } from '@/stores'
+import { useNavigation } from '@mobile/router/navigation'
+import { fullloading } from '@/utils/vant'
+import { decryptAES } from '@/services/websocket/package/crypto'
+
+// formRef
+const formRef = shallowRef<FormInstance>()
+// loginStore
+const loginStore = useLoginStore()
+// userStore
+const userStore = useUserStore()
+// router
+const { router } = useNavigation()
+
+const formData = reactive<Model.UserInfoWechatAndEmailReq>({
+    userid: loginStore.userId, // 用户ID
+    wechat: decryptAES(userStore.userInfo.wechat), //  微信
+})
+
+// 表单验证规则
+const formRules: { [key in keyof Model.UserInfoWechatAndEmailReq]?: FieldRule[] } = {
+    wechat: [{
+        message: '请输入微信号',
+        validator: () => {
+            return !!formData.wechat
+        }
+    }],
+}
+
+const onSubmit = () => {
+    fullloading((hideLoading) => {
+        updateUserInfoWechatAndEmail({
+            data: formData
+        }).then(() => {
+            hideLoading()
+            router.back()
+        }).catch((err) => {
+            showFailToast(err)
+        })
+    })
+}
+</script>

+ 1 - 1
src/packages/sbyj/router/index.ts

@@ -118,7 +118,7 @@ const routes: Array<RouteRecordRaw> = [
       {
         path: 'certification',
         name: 'account-certification',
-        component: () => import('@mobile/views/account/certification/Index.vue'),
+        component: () => import('../views/account/certification/Index.vue'),
       },
       {
         path: 'protocol',

+ 11 - 0
src/services/api/user/index.ts

@@ -106,6 +106,17 @@ export function updateUserHeadUrl(config: RequestConfig<Model.UserHeadUrlReq> =
 }
 
 /**
+ * 更新用户微信和邮箱
+ */
+export function updateUserInfoWechatAndEmail(config: RequestConfig<Model.UserInfoWechatAndEmailReq> = {}) {
+    return http.commonRequest({
+        method: 'post',
+        url: '/User/UpdateUserInfoWechatAndEmail',
+        data: config.data,
+    })
+}
+
+/**
  * 登录账号、手机号精确查询用户
  */
 export function getUserInfo(config: RequestConfig<Model.UserInfoReq> = {}) {

+ 7 - 0
src/types/model/user.d.ts

@@ -5,6 +5,13 @@ declare namespace Model {
         headurl: string;
     }
 
+    /** 更新用户微信和邮箱 请求 */
+    interface UserInfoWechatAndEmailReq {
+        userid: number; // 用户ID
+        email?: string;  // 用户邮箱
+        wechat?: string; // 用户微信号
+    }
+
     /** 查询收货地址信息 请求 */
     interface UserReceiveInfoReq {
         userid?: number; // 用户ID