Explorar el Código

feat(api): api update 32

gemercheung hace 3 años
padre
commit
57ebbd2547
Se han modificado 4 ficheros con 93 adiciones y 52 borrados
  1. 6 0
      src/api/sys/model/userModel.ts
  2. 14 1
      src/api/sys/user.ts
  3. 39 25
      src/views/setting/BaseSetting.vue
  4. 34 26
      src/views/setting/data.ts

+ 6 - 0
src/api/sys/model/userModel.ts

@@ -16,6 +16,12 @@ export interface LoginParams {
   userName?: string;
 }
 
+export interface updateUserInfoPasswordParam {
+  id: string | number;
+  password: string;
+  newPassword: string;
+}
+
 export interface RoleInfo {
   userID?: string;
   roleName: string;

+ 14 - 1
src/api/sys/user.ts

@@ -1,5 +1,10 @@
 import { defHttp } from '/@/utils/http/axios';
-import { LoginParams, LoginResultModel, GetUserInfoModel } from './model/userModel';
+import {
+  LoginParams,
+  LoginResultModel,
+  GetUserInfoModel,
+  updateUserInfoPasswordParam,
+} from './model/userModel';
 import { encodeStr } from '/@/utils/encodeUtil';
 import { ErrorMessageMode } from '/#/axios';
 import { ContentTypeEnum } from '/@/enums/httpEnum';
@@ -13,6 +18,7 @@ enum Api {
   Logout = '/logout',
   // GetUserInfo = '/zfb-api/zfb/shop/sys/user/infoAnon',
   GetUserInfo = '/kankan-api/api/user/getUserInfo',
+  updatePassword = '/kankan-api/api/manager/user/updatePassword',
   GetPermCode = '/getPermCode',
 }
 
@@ -58,3 +64,10 @@ export function getPermCode() {
 export function doLogout() {
   return defHttp.get({ url: Api.Logout });
 }
+
+export function updatePasswordApi(params: updateUserInfoPasswordParam) {
+  return defHttp.post<GetUserInfoModel>(
+    { url: Api.updatePassword, params },
+    // { errorMessageMode: 'none' },
+  );
+}

+ 39 - 25
src/views/setting/BaseSetting.vue

@@ -1,8 +1,11 @@
 <template>
   <CollapseContainer title="基本设置" :canExpan="false">
     <a-row :gutter="24">
-      <a-col :span="14">
+      <a-col :span="10">
         <BasicForm @register="register" />
+        <div class="px-5 py-15 flex justify-center">
+          <Button type="primary" @click="handleSubmit"> 更新基本信息 </Button>
+        </div>
       </a-col>
       <!-- <a-col :span="10">
         <div class="change-avatar">
@@ -18,23 +21,23 @@
         </div>
       </a-col> -->
     </a-row>
-    <Button type="primary" @click="handleSubmit"> 更新基本信息 </Button>
   </CollapseContainer>
 </template>
 <script lang="ts">
   import { Button, Row, Col } from 'ant-design-vue';
-  import { computed, defineComponent, onMounted } from 'vue';
+  import { defineComponent, onMounted } from 'vue';
   import { BasicForm, useForm } from '/@/components/Form/index';
   import { CollapseContainer } from '/@/components/Container';
   // import { CropperAvatar } from '/@/components/Cropper';
 
-  import { useMessage } from '/@/hooks/web/useMessage';
+  // import { useMessage } from '/@/hooks/web/useMessage';
 
-  import headerImg from '/@/assets/images/header.jpg';
-  import { accountInfoApi } from '/@/api/account/index';
+  // import headerImg from '/@/assets/images/header.jpg';
+  // import { accountInfoApi } from '/@/api/account/index';
   import { baseSetschemas } from './data';
   import { useUserStore } from '/@/store/modules/user';
-  import { uploadApi } from '/@/api/sys/upload';
+  import { updatePasswordApi } from '/@/api/sys/user';
+  import { encodeStr } from '/@/utils/encodeUtil';
 
   export default defineComponent({
     components: {
@@ -46,39 +49,50 @@
       // CropperAvatar,
     },
     setup() {
-      const { createMessage } = useMessage();
+      // const { createMessage } = useMessage();
       const userStore = useUserStore();
 
-      const [register, { setFieldsValue }] = useForm({
+      const [register, { validate }] = useForm({
         labelWidth: 120,
         schemas: baseSetschemas,
         showActionButtonGroup: false,
       });
 
       onMounted(async () => {
-        const data = await accountInfoApi();
-        setFieldsValue(data);
+        // const data = await accountInfoApi();
+        // setFieldsValue(data);
       });
 
-      const avatar = computed(() => {
-        const { avatar } = userStore.getUserInfo;
-        return avatar || headerImg;
-      });
+      // const avatar = computed(() => {
+      //   const { avatar } = userStore.getUserInfo;
+      //   return avatar || headerImg;
+      // });
 
-      function updateAvatar(src: string) {
-        const userinfo = userStore.getUserInfo;
-        userinfo.avatar = src;
-        userStore.setUserInfo(userinfo);
+      // function updateAvatar(src: string) {
+      //   const userinfo = userStore.getUserInfo;
+      //   userinfo.avatar = src;
+      //   userStore.setUserInfo(userinfo);
+      // }
+      async function handleSubmit() {
+        try {
+          const values = await validate();
+          const userInfo = userStore.getUserInfo;
+          console.log('userInfo', values, userInfo);
+          const res = await updatePasswordApi({
+            id: userInfo.id,
+            password: encodeStr(values.password),
+            newPassword: encodeStr(values.newPassword),
+          });
+          console.log('res', res);
+        } catch (error) {}
       }
 
       return {
-        avatar,
+        // avatar,
         register,
-        uploadApi: uploadApi as any,
-        updateAvatar,
-        handleSubmit: () => {
-          createMessage.success('更新成功!');
-        },
+        // uploadApi: uploadApi as any,
+        // updateAvatar,
+        handleSubmit,
       };
     },
   });

+ 34 - 26
src/views/setting/data.ts

@@ -36,35 +36,43 @@ export const settingList = [
 // 基础设置 form
 export const baseSetschemas: FormSchema[] = [
   {
-    field: 'email',
-    component: 'Input',
-    label: '邮箱',
-    colProps: { span: 18 },
+    field: 'password',
+    component: 'StrengthMeter',
+    label: '旧密码',
+    required: true,
+    // colProps: { span: 18 },
   },
   {
-    field: 'name',
-    component: 'Input',
-    label: '昵称',
-    colProps: { span: 18 },
-  },
-  {
-    field: 'introduction',
-    component: 'InputTextArea',
-    label: '个人简介',
-    colProps: { span: 18 },
-  },
-  {
-    field: 'phone',
-    component: 'Input',
-    label: '联系电话',
-    colProps: { span: 18 },
-  },
-  {
-    field: 'address',
-    component: 'Input',
-    label: '所在地区',
-    colProps: { span: 18 },
+    field: 'newPassword',
+    component: 'StrengthMeter',
+    label: '新密码',
+    required: true,
+    // colProps: { span: 18 },
   },
+  // {
+  //   field: 'name',
+  //   component: 'Input',
+  //   label: '昵称',
+  //   colProps: { span: 18 },
+  // },
+  // {
+  //   field: 'introduction',
+  //   component: 'InputTextArea',
+  //   label: '个人简介',
+  //   colProps: { span: 18 },
+  // },
+  // {
+  //   field: 'phone',
+  //   component: 'Input',
+  //   label: '联系电话',
+  //   colProps: { span: 18 },
+  // },
+  // {
+  //   field: 'address',
+  //   component: 'Input',
+  //   label: '所在地区',
+  //   colProps: { span: 18 },
+  // },
 ];
 
 // 安全设置 list