فهرست منبع

Merge branch 'feature/mockApi' of http://192.168.0.115:3000/zhangyupeng/zfb_mp into feature/mockApi

gemercheung 3 سال پیش
والد
کامیت
86e0e27138

+ 1 - 1
.env.development

@@ -6,7 +6,7 @@ VITE_PUBLIC_PATH = /
 
 # Cross-domain proxy, you can configure multiple
 # Please note that no line breaks
-VITE_PROXY = [["/basic-api","http://192.168.0.47:8190"],["/upload","http://localhost:3300/upload"],["/zfb-api","https://cszfb.4dkankan.com"]]
+VITE_PROXY = [["/basic-api","http://192.168.0.47:8190"],["/upload","http://localhost:3300/upload"],["/zfb-api","http://192.168.0.47:7081"]]
 # VITE_PROXY=[["/api","https://vvbin.cn/test"]]
 
 # Delete console

+ 2 - 1
.env.production

@@ -16,7 +16,8 @@ VITE_BUILD_COMPRESS = 'none'
 VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE = false
 
 # Basic interface address SPA
-VITE_GLOB_API_URL=/basic-api
+# VITE_GLOB_API_URL=/basic-api
+VITE_GLOB_API_URL=
 
 # File upload address, optional
 # It can be forwarded by nginx or write the actual address directly

+ 3 - 3
docker/setting/proxy.conf

@@ -1,7 +1,7 @@
-location /mall/ {
+location /basic-api/ {
     proxy_pass http://192.168.0.47:8190/;
 }
 
-location /zfb/ {
-    proxy_pass http:/192.168.0.47:7081/zfb/;
+location /zfb-api/ {
+    proxy_pass http://192.168.0.47:7081/;
 }

+ 2 - 2
mock/_util.ts

@@ -47,7 +47,7 @@ export function pagination<T = any>(pageNo: number, pageSize: number, array: T[]
 export interface requestParams {
   method: string;
   body: any;
-  headers?: { authorization?: string };
+  headers?: { token?: string };
   query: any;
 }
 
@@ -56,5 +56,5 @@ export interface requestParams {
  *
  */
 export function getRequestToken({ headers }: requestParams): string | undefined {
-  return headers?.authorization;
+  return headers?.token;
 }

+ 1 - 1
package.json

@@ -4,7 +4,7 @@
   "scripts": {
     "bootstrap": "pnpm install",
     "serve": "npm run dev",
-    "dev": "vite",
+    "dev": "vite --debug",
     "build": "cross-env NODE_ENV=production vite build && esno ./build/script/postBuild.ts",
     "build:test": "cross-env vite build --mode test && esno ./build/script/postBuild.ts",
     "build:no-cache": "pnpm clean:cache && npm run build",

+ 52 - 0
src/api/corporation/modal.ts

@@ -0,0 +1,52 @@
+import { defHttp } from '/@/utils/http/axios';
+import { selectUserListParam, checkDeiceParam, addDeiceParam } from './model';
+import type { Result } from '/#/axios';
+
+enum Api {
+  addDevice = '/zfb-api/zfb/company/addDevice',
+  checkDevice = '/zfb-api/zfb/company/checkDevice',
+  selectUserList = '/zfb-api/zfb/company/selectUserList',
+  saveSubUsers = '/zfb-api/zfb/company/saveSubUsers',
+}
+
+/**
+ * @description: Get sample list value
+ */
+
+export const AddDevice = (params: addDeiceParam) =>
+  defHttp.post<Result>({
+    url: Api.addDevice,
+    params,
+    headers: {
+      // @ts-ignore
+      ignoreCancelToken: true,
+    },
+  });
+
+export const checkDevice = (params: checkDeiceParam) =>
+  defHttp.post<Result>({
+    url: Api.checkDevice,
+    params,
+    headers: {
+      // @ts-ignore
+      ignoreCancelToken: true,
+    },
+  });
+export const selectUserList = (params: selectUserListParam) =>
+  defHttp.post<Result>({
+    url: Api.selectUserList,
+    params,
+    headers: {
+      // @ts-ignore
+      ignoreCancelToken: true,
+    },
+  });
+export const saveSubUsers = (params: selectUserListParam) =>
+  defHttp.post<Result>({
+    url: Api.saveSubUsers,
+    params,
+    headers: {
+      // @ts-ignore
+      ignoreCancelToken: true,
+    },
+  });

+ 56 - 0
src/api/corporation/model.ts

@@ -3,7 +3,63 @@ import { BasicPageParams, BasicFetchResult } from '/@/api/model/baseModel';
  * @description: Request list interface parameters
  */
 export type PageParams = BasicPageParams;
+export interface addDeiceParam {
+  childName: string | null;
+  id: number;
+  subNum: number;
+  userName: string;
+}
+export interface checkDeiceParam {
+  childName: string | null;
+}
+
+export interface selectUserListParam {
+  id: number | null;
+}
+export interface SubAccountUsers {
+  id: number | null;
+  subNum: string | null;
+  subUsers: SubAccountUser[];
+}
 
+export interface SubAccountUser {
+  appid: string | number | null;
+  companyId: string | number | null;
+  createTime: string | number | null;
+  createUser: string | number | null;
+  fdkkPassword: string | number | null;
+  fdkkUser: string | number | null;
+  head: string | number | null;
+  id: number | null;
+  memoName: string | null;
+  message: string | number | null;
+  nickName: string | null;
+  phone: string | null;
+  state: string | number | null;
+  token: string | number | null;
+  type: string | number | null;
+  updateTime: string | number | null;
+  updateUser: string | number | null;
+  userName: string | null;
+  userPassword: string | number | null;
+}
+
+export interface ListItem {
+  id: number;
+  bgMusic: string;
+  cameraNum: string;
+  childName: string;
+  expirationDate: string;
+  expirationTime: string;
+  floorLogo: string;
+  name: string;
+  num: string;
+  point: string;
+  sceneLogo: string;
+  sceneNum: string;
+  subNum: string;
+  userName: string;
+}
 export interface ListItem {
   id: number;
   bgMusic: string;

+ 2 - 2
src/api/feedback/list.ts

@@ -2,7 +2,7 @@ import { defHttp } from '/@/utils/http/axios';
 import { PageParams, RentListGetResultModel } from './model';
 
 enum Api {
-  pageList = '/zfb/feedback/list',
+  pageList = '/basic-api/feedback/list',
 }
 
 /**
@@ -10,7 +10,7 @@ enum Api {
  */
 
 export const ListApi = (params: PageParams) =>
-  defHttp.get<RentListGetResultModel>({
+  defHttp.post<RentListGetResultModel>({
     url: Api.pageList,
     params,
     headers: {

+ 1 - 1
src/api/member/list.ts

@@ -2,7 +2,7 @@ import { defHttp } from '/@/utils/http/axios';
 import { PageParams, MemberListGetResultModel } from './model';
 
 enum Api {
-  pageList = '/zfb/member/list',
+  pageList = '/basic-api/member/list',
 }
 
 /**

+ 2 - 2
src/api/order/list.ts

@@ -2,7 +2,7 @@ import { defHttp } from '/@/utils/http/axios';
 import { PageParams, RentListGetResultModel } from './model';
 
 enum Api {
-  pageList = '/zfb/order/list',
+  pageList = '/basic-api/order/list',
 }
 
 /**
@@ -10,7 +10,7 @@ enum Api {
  */
 
 export const ListApi = (params: PageParams) =>
-  defHttp.get<RentListGetResultModel>({
+  defHttp.post<RentListGetResultModel>({
     url: Api.pageList,
     params,
     headers: {

+ 2 - 2
src/api/product/list.ts

@@ -2,8 +2,8 @@ import { defHttp } from '/@/utils/http/axios';
 import { PageParams, RentListGetResultModel } from './model';
 
 enum Api {
-  pageList = '/zfb/product/list',
-  category = '/zfb/product/category',
+  pageList = '/basic-api/product/list',
+  category = '/basic-api/product/category',
 }
 
 /**

+ 1 - 1
src/api/staff/list.ts

@@ -2,7 +2,7 @@ import { defHttp } from '/@/utils/http/axios';
 import { PageParams, RentListGetResultModel } from './model';
 
 enum Api {
-  pageList = '/zfb/staff/list',
+  pageList = '/basic-api/sys/user/staffList',
 }
 
 /**

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

@@ -4,6 +4,7 @@
 export interface LoginParams {
   username: string;
   password: string;
+  captcha: string;
 }
 
 export interface RoleInfo {

+ 4 - 3
src/api/sys/user.ts

@@ -1,6 +1,6 @@
 import { defHttp } from '/@/utils/http/axios';
 import { LoginParams, LoginResultModel, GetUserInfoModel } from './model/userModel';
-
+import { encodeStr } from '/@/utils/encodeUtil';
 import { ErrorMessageMode } from '/#/axios';
 
 enum Api {
@@ -15,9 +15,10 @@ enum Api {
  */
 export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
   const form = new FormData();
+  const encryptPassword: string = encodeStr(window.btoa(params.password));
   form.append('username', params.username);
-  form.append('password', params.password);
-  form.append('captcha', '11111');
+  form.append('password', encryptPassword);
+  form.append('captcha', params.captcha);
   return defHttp.post<LoginResultModel>(
     {
       url: Api.Login,

+ 1 - 1
src/components/Form/src/types/form.ts

@@ -10,7 +10,7 @@ import type { RowProps } from 'ant-design-vue/lib/grid/Row';
 export type FieldMapToTime = [string, [string, string], string?][];
 
 export type Rule = RuleObject & {
-  trigger?: 'blur' | 'change' | ['change', 'blur'];
+  trigger?: 'blur' | 'change' | 'blur' | ['change', 'blur', 'blur'];
 };
 
 export interface RenderCallbackParams {

+ 2 - 1
src/store/modules/user.ts

@@ -91,8 +91,9 @@ export const useUserStore = defineStore({
       try {
         const { goHome = true, mode, ...loginParams } = params;
         const data = await loginApi(loginParams, mode);
+        const { token, user } = data;
 
-        const { token } = data;
+        console.log('user', user);
 
         // save token
         this.setToken(token);

+ 99 - 0
src/utils/encodeUtil.ts

@@ -0,0 +1,99 @@
+/*
+ ** 登录密码加密
+  http://face3d.4dage.com:7005/4dzfb-2.0/shop/src/master/platform-admin/src/main/webapp/login.html
+ */
+function randomWord(randomFlag, min, max?) {
+  let str = '';
+  let range = min;
+  const arr = [
+    '0',
+    '1',
+    '2',
+    '3',
+    '4',
+    '5',
+    '6',
+    '7',
+    '8',
+    '9',
+    'a',
+    'b',
+    'c',
+    'd',
+    'e',
+    'f',
+    'g',
+    'h',
+    'i',
+    'j',
+    'k',
+    'l',
+    'm',
+    'n',
+    'o',
+    'p',
+    'q',
+    'r',
+    's',
+    't',
+    'u',
+    'v',
+    'w',
+    'x',
+    'y',
+    'z',
+    'A',
+    'B',
+    'C',
+    'D',
+    'E',
+    'F',
+    'G',
+    'H',
+    'I',
+    'J',
+    'K',
+    'L',
+    'M',
+    'N',
+    'O',
+    'P',
+    'Q',
+    'R',
+    'S',
+    'T',
+    'U',
+    'V',
+    'W',
+    'X',
+    'Y',
+    'Z',
+  ];
+  // 随机产生
+  if (randomFlag) {
+    range = Math.round(Math.random() * (max - min)) + min;
+  }
+  for (let i = 0; i < range; i++) {
+    const pos = Math.round(Math.random() * (arr.length - 1));
+    str += arr[pos];
+  }
+  return str;
+}
+
+export function encodeStr(str, strv = ''): string {
+  const NUM = 2;
+  const front = randomWord(false, 8);
+  const middle = randomWord(false, 8);
+  const end = randomWord(false, 8);
+
+  const str1 = str.substring(0, NUM);
+  const str2 = str.substring(NUM);
+
+  if (strv) {
+    const strv1 = strv.substring(0, NUM);
+    const strv2 = strv.substring(NUM);
+    return [front + str2 + middle + str1 + end, front + strv2 + middle + strv1 + end];
+  }
+
+  return front + str2 + middle + str1 + end;
+}

+ 11 - 9
src/utils/http/axios/index.ts

@@ -50,7 +50,7 @@ const transform: AxiosTransform = {
     }
     //  这里 code,result,message为 后台统一的字段,需要在 types.ts内修改为项目自己的接口返回格式
 
-    const { code, result, message } = data;
+    const { code, error, message } = data;
     // TODO
     // 这里逻辑可以根据项目进行修改
     const hasSuccess =
@@ -58,11 +58,13 @@ const transform: AxiosTransform = {
       Reflect.has(data, 'code') &&
       (code === ResultEnum.SUCCESS || code === ResultEnum.NORMAL);
     if (hasSuccess) {
-      if (typeof message === 'object' && Reflect.has(message, 'pageSize')) {
-        return message;
-      } else {
-        return result || data;
-      }
+      const converterResult = data.message;
+      const converterMessage = error;
+      data.result = converterResult;
+      data.message = converterMessage;
+      delete data.error;
+
+      return data.result || data;
     }
 
     // 在此处根据自己项目的实际情况对不同的code执行不同的操作
@@ -149,9 +151,9 @@ const transform: AxiosTransform = {
     const token = getToken();
     if (token && (config as Recordable)?.requestOptions?.withToken !== false) {
       // jwt token
-      (config as Recordable).headers.Authorization = options.authenticationScheme
-        ? `${options.authenticationScheme} ${token}`
-        : token;
+      // (config as Recordable).headers.Authorization = options.authenticationScheme
+      //   ? `${options.authenticationScheme} ${token}`
+      //   : token;
       (config as Recordable).headers.token = options.authenticationScheme
         ? `${options.authenticationScheme} ${token}`
         : token;

+ 73 - 0
src/views/dashboard/corporation/EditModal.vue

@@ -0,0 +1,73 @@
+<template>
+  <BasicModal
+    v-bind="$attrs"
+    @register="register"
+    title="修改子账号"
+    @visible-change="handleVisibleChange"
+    @ok="submitMolad"
+  >
+    <div class="pt-3px pr-3px">
+      <BasicForm @register="registerForm" :model="model" />
+    </div>
+  </BasicModal>
+</template>
+<script lang="ts">
+  import { defineComponent, ref, nextTick } from 'vue';
+  import { BasicModal, useModalInner } from '/@/components/Modal';
+  import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
+  const schemas: FormSchema[] = [
+    {
+      field: 'memoName',
+      component: 'Input',
+      label: '姓名',
+      colProps: {
+        span: 24,
+      },
+    },
+    {
+      field: 'phone',
+      component: 'Input',
+      label: '手机号',
+      colProps: {
+        span: 24,
+      },
+    },
+  ];
+  export default defineComponent({
+    components: { BasicModal, BasicForm },
+    props: {
+      userData: { type: Object },
+    },
+    setup(props) {
+      const modelRef = ref({});
+      const [registerForm, { setFieldsValue, getFieldsValue }] = useForm({
+        labelWidth: 120,
+        schemas,
+        showActionButtonGroup: false,
+        actionColOptions: {
+          span: 24,
+        },
+      });
+
+      const [register] = useModalInner((data) => {
+        data && onDataReceive(data);
+      });
+      function submitMolad() {
+        console.log('handleSubmit', getFieldsValue());
+      }
+      function onDataReceive(data) {
+        console.log('Data Received', data);
+        // 方式1;
+        setFieldsValue({ ...data });
+        // // 方式2
+        modelRef.value = { ...data };
+      }
+
+      function handleVisibleChange(v) {
+        v && props.userData && nextTick(() => onDataReceive(props.userData));
+      }
+
+      return { register, submitMolad, schemas, registerForm, model: modelRef, handleVisibleChange };
+    },
+  });
+</script>

+ 215 - 0
src/views/dashboard/corporation/SubaccountModal.vue

@@ -0,0 +1,215 @@
+<template>
+  <BasicModal
+    v-bind="$attrs"
+    @register="register"
+    title="设备"
+    @visible-change="handleVisibleChange"
+  >
+    <div class="pt-3px pr-3px">
+      <BasicForm @register="registerForm" :model="modelRef">
+        <template #userName="{ model, field }">
+          {{ model[field] }}
+        </template>
+        <template #name="{ model, field }">
+          {{ model[field] }}
+        </template>
+        <template #addeduser="{ model, field }">
+          {{ model[field] || 10 }}
+          <a-button type="primary" preIcon="ic:outline-person-add"> 新增子账号 </a-button>
+        </template>
+      </BasicForm>
+      <div class="table_list">
+        <BasicTable @register="registerTable" :canResize="true">
+          <template #action="{ record }">
+            <TableAction
+              :actions="[
+                {
+                  label: '编辑',
+                  icon: 'mdi:account-edit-outline',
+                  onClick: handleDelete.bind(null, record, 'edit'),
+                },
+                {
+                  label: '解绑',
+                  icon: 'mdi:account-multiple-remove-outline',
+                  onClick: handleDelete.bind(null, record, 'unbond'),
+                },
+              ]"
+            />
+          </template>
+        </BasicTable>
+      </div>
+    </div>
+    <EditModal @register="registerEdit" />
+  </BasicModal>
+</template>
+<script lang="ts">
+  import { defineComponent, ref, nextTick } from 'vue';
+  import { BasicModal, useModalInner, useModal } from '/@/components/Modal';
+  import { BasicTable, useTable, BasicColumn, TableAction } from '/@/components/Table';
+  import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
+  import { selectUserList } from '/@/api/corporation/modal';
+  import { useMessage } from '/@/hooks/web/useMessage';
+  import EditModal from './EditModal.vue';
+  export default defineComponent({
+    components: { BasicModal, BasicForm, BasicTable, TableAction, EditModal },
+    props: {
+      userData: { type: Object },
+    },
+    setup(props) {
+      const { createConfirm } = useMessage();
+      const modelRef = ref({});
+      // const editList = ref({
+      //   list:[]
+      // })
+      const columns: BasicColumn[] = [
+        {
+          title: '姓名',
+          dataIndex: 'memoName',
+          width: 100,
+        },
+        {
+          title: '手机号',
+          dataIndex: 'phone',
+          width: 150,
+        },
+      ];
+      const [registerTable, { setProps, reload }] = useTable({
+        title: '子账户列表',
+        api: selectUserList,
+        pagination: false,
+        columns: columns,
+        rowKey: 'id',
+        fetchSetting: {
+          pageField: 'pageNum',
+          sizeField: 'pageSize',
+          listField: 'list',
+          totalField: 'total',
+        },
+        afterFetch: (T) => {
+          console.log('afterFetch', T);
+          return T;
+        },
+        actionColumn: {
+          width: 160,
+          title: '操作',
+          dataIndex: 'action',
+          slots: { customRender: 'action' },
+        },
+      });
+      const schemas: FormSchema[] = [
+        {
+          field: 'userName',
+          component: 'Input',
+          label: '充值账号',
+          slot: 'userName',
+          labelWidth: 200,
+        },
+        {
+          field: 'name',
+          label: '企业账号',
+          slot: 'name',
+          component: 'Input',
+          labelWidth: 200,
+        },
+        {
+          field: 'subNum',
+          component: 'InputNumber',
+          label: '设备数量',
+          labelWidth: 200,
+          componentProps: () => {
+            return {
+              // xxxx props schema, tableAction, formModel  checkDevice
+              min: 0,
+              onChange: numOnChange,
+            };
+          },
+        },
+        {
+          field: 'addeduser',
+          label: '已添加字子号账号数',
+          labelWidth: 200,
+          slot: 'addeduser',
+          component: 'Input',
+        },
+      ];
+      const [
+        registerForm,
+        {
+          setFieldsValue,
+          resetFields,
+          // setProps,
+        },
+      ] = useForm({
+        labelWidth: 120,
+        schemas,
+        showActionButtonGroup: false,
+        actionColOptions: {
+          span: 24,
+        },
+      });
+      const [registerEdit, { openModal: EditModal }] = useModal();
+      const [register] = useModalInner((data) => {
+        data && onDataReceive(data);
+      });
+
+      function onDataReceive(data) {
+        console.log('Data Received', data.record);
+        // 方式1;
+        resetFields();
+        setFieldsValue({
+          ...data.record,
+        });
+
+        // // 方式2
+        modelRef.value = { ...data.record };
+        let { id } = data.record;
+        setProps({
+          searchInfo: {
+            id,
+          },
+        });
+        reload();
+      }
+      function numOnChange(event) {
+        console.log('numOnChange', event);
+      }
+      async function handleDelete(item, type) {
+        console.log('handleDelete', item, type);
+        if (type == 'edit') {
+          //编辑
+          const { memoName, phone } = item;
+          EditModal(true, {
+            memoName,
+            phone,
+          });
+        } else {
+          //解除
+          let confirm = await createConfirm({
+            iconType: 'warning',
+            title: '提示',
+            content: '确定要解绑该子账号?',
+            onOk: async () => {
+              // await this.logout(true);
+            },
+          });
+          console.log('confirm', confirm);
+        }
+      }
+      function handleVisibleChange(v) {
+        v && props.userData && nextTick(() => onDataReceive(props.userData));
+      }
+
+      return {
+        register,
+        handleDelete,
+        registerEdit,
+        numOnChange,
+        registerTable,
+        schemas,
+        registerForm,
+        modelRef,
+        handleVisibleChange,
+      };
+    },
+  });
+</script>

+ 228 - 0
src/views/dashboard/corporation/deviceModal.vue

@@ -0,0 +1,228 @@
+<template>
+  <BasicModal
+    v-bind="$attrs"
+    @register="register"
+    title="新增设备"
+    @ok="submitMolad"
+    @visible-change="handleVisibleChange"
+  >
+    <div class="pt-3px pr-3px">
+      <BasicForm @register="registerForm">
+        <template #userName="{ model, field }">
+          {{ model[field] }}
+        </template>
+        <template #name="{ model, field }">
+          {{ model[field] }}
+        </template>
+      </BasicForm>
+    </div>
+  </BasicModal>
+</template>
+<script lang="ts">
+  import { defineComponent, ref, nextTick } from 'vue';
+  import { BasicModal, useModalInner } from '/@/components/Modal';
+  import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
+  import { useMessage } from '/@/hooks/web/useMessage';
+  import { AddDevice, checkDevice } from '/@/api/corporation/modal';
+  export default defineComponent({
+    components: { BasicModal, BasicForm },
+    props: {
+      userData: { type: Object },
+    },
+    setup(props) {
+      const modelRef = ref({});
+      const num = ref(0);
+      const { createMessage } = useMessage();
+      const { success, error } = createMessage;
+      // const debounce = (fn, delay) => {
+      //   var timer = null;
+      //   return function () {
+      //     var context = this, args = arguments;
+      //     clearTimeout(timer);
+      //     timer = setTimeout(function () {
+      //       fn.apply(context, args);
+      //     }, delay);
+      //   };
+      // }
+      const [register, { closeModal }] = useModalInner((data) => {
+        data && onDataReceive(data);
+      });
+
+      const handlevalidator = async (_, value) => {
+        console.log('handlevalidator', value);
+        if (!value) {
+          return Promise.resolve();
+        }
+        try {
+          let res = await checkDevice({
+            childName: value,
+          });
+          if (res.message) {
+            return Promise.reject(res.message);
+          } else {
+            return Promise.resolve();
+          }
+        } catch (err) {
+          return Promise.reject(err);
+        }
+      };
+      const schemas: FormSchema[] = [
+        {
+          field: 'userName',
+          label: '企业名称',
+          slot: 'userName',
+          component: 'Input',
+        },
+        {
+          field: 'name',
+          label: '企业账号',
+          slot: 'name',
+          component: 'Input',
+        },
+        {
+          field: 'num',
+          component: 'InputNumber',
+          label: '设备数量',
+          colProps: {
+            span: 8,
+          },
+          componentProps: () => {
+            return {
+              // xxxx props schema, tableAction, formModel  checkDevice
+              min: 0,
+              onChange: numOnChange,
+            };
+          },
+        },
+      ];
+      // let schemasList = []
+      const [
+        registerForm,
+        {
+          setFieldsValue,
+          resetFields,
+          getFieldsValue,
+          validateFields,
+          appendSchemaByField,
+          removeSchemaByFiled,
+        },
+      ] = useForm({
+        labelWidth: 120,
+        schemas,
+        showActionButtonGroup: false,
+        actionColOptions: {
+          span: 24,
+        },
+      });
+      async function submitMolad() {
+        let formData = {
+          ...getFieldsValue(),
+        };
+        let validate = false;
+        try {
+          const res = await validateFields();
+          validate = true;
+          console.log('passing', res, formData);
+        } catch (error: unknown) {
+          console.log('not passing', error);
+        }
+        if (validate) {
+          const { subNum, id, userName } = modelRef.value;
+          try {
+            const res = await AddDevice({
+              childName: null,
+              id,
+              subNum,
+              userName,
+            });
+            if (res.code == 200) {
+              success(res.message);
+              closeModal();
+            }
+          } catch (errors) {
+            error('errors');
+            console.log('not passing', error);
+          }
+        }
+      }
+      function onDataReceive(data) {
+        // 方式1;
+        resetFields();
+        setFieldsValue({
+          ...data.record,
+        });
+
+        // // 方式2
+        modelRef.value = { ...data.record };
+
+        // setProps({
+        //   ...data.record,
+        // });
+      }
+      function numOnChange(event) {
+        const value = Number(event);
+        if (num.value > value) {
+          //减
+          let delList = Array.from(new Array(num.value)).map((_, index) => {
+            console.log(index, value, num.value);
+            if (index >= value) {
+              return `ID${index}`;
+            }
+          });
+          removeSchemaByFiled(delList);
+          console.log('schemasList减', value, num.value, delList);
+          // value,num.value,schemasList.filter((_,index) => {return !(index<num.value)}).map((_,index) => `ID${index}`))
+        } else {
+          //增
+          let schemasList: FormSchema[] = Array.from(new Array(value)).map((_, index) => {
+            return {
+              field: `ID${index}`,
+              component: 'Input',
+              label: '设备ID' + index,
+              itemProps: {
+                validateTrigger: 'blur',
+              },
+              colProps: {
+                span: 24,
+              },
+              rules: [
+                {
+                  required: false,
+                  trigger: 'blur',
+                  validator: handlevalidator,
+                },
+              ],
+            };
+          });
+          console.log(
+            'schemasList增',
+            num.value,
+            schemasList.filter((_, index) => {
+              return index >= num.value;
+            }),
+          );
+          schemasList
+            .filter((_, index) => {
+              return index >= num.value;
+            })
+            .forEach((item) => appendSchemaByField(item, ''));
+        }
+        num.value = value;
+      }
+      function handleVisibleChange(v) {
+        v && props.userData && nextTick(() => onDataReceive(props.userData));
+      }
+      return {
+        register,
+        submitMolad,
+        schemas,
+        registerForm,
+        numOnChange,
+        model: modelRef,
+        handleVisibleChange,
+        num,
+        errorMsg: error,
+      };
+    },
+  });
+</script>

+ 34 - 10
src/views/dashboard/corporation/index.vue

@@ -36,24 +36,26 @@
             {
               // icon: 'ri:money-cny-circle-fill',
               label: '充值',
-              onClick: handleOpenChargeModal.bind(null, record),
+              onClick: handleOpenModal.bind(null, 'charge', record),
             },
             {
               // icon: 'icon-park-outline:devices',
               label: '设备',
-              onClick: () => {},
+              onClick: handleOpenModal.bind(null, 'device', record),
             },
             {
               // icon: 'mdi:account-group',
               color: 'error',
               label: '子账号',
-              onClick: handleOpenChargeModal.bind(null, record),
+              onClick: handleOpenModal.bind(null, 'sub_account', record),
             },
           ]"
         />
       </template>
     </BasicTable>
     <chargeModal @register="registerChargeModal" />
+    <deviceModal @register="registerDeviceModal" />
+    <SubaccountModal @register="registerSubaccountModal" />
   </div>
 </template>
 <script lang="ts">
@@ -67,13 +69,24 @@
   import { ListApi } from '/@/api/corporation/list';
   import { useModal } from '/@/components/Modal';
   import chargeModal from './chargeModal.vue';
+  import deviceModal from './deviceModal.vue';
+  import SubaccountModal from './SubaccountModal.vue';
   import { Time } from '/@/components/Time';
 
   export default defineComponent({
-    components: { BasicTable, CropperAvatar, TableAction, chargeModal, Time },
+    components: {
+      BasicTable,
+      CropperAvatar,
+      TableAction,
+      chargeModal,
+      deviceModal,
+      SubaccountModal,
+      Time,
+    },
     setup() {
       const [registerChargeModal, { openModal: openChargeModal }] = useModal();
-
+      const [registerDeviceModal, { openModal: openDeviceModal }] = useModal();
+      const [registerSubaccountModal, { openModal: openSubaccountModal }] = useModal();
       const columns: BasicColumn[] = [
         {
           title: 'ID',
@@ -185,16 +198,27 @@
           slots: { customRender: 'action' },
         },
       });
-      function handleOpenChargeModal(record: Recordable) {
-        openChargeModal(true, {
-          record,
-        });
+      function handleOpenModal(val, record: Recordable) {
+        let listKey = {
+          charge: openChargeModal,
+          device: openDeviceModal,
+          sub_account: openSubaccountModal,
+        };
+        listKey[val] &&
+          listKey[val](true, {
+            record,
+          });
+        // openChargeModal(true, {
+        //   record,
+        // });
       }
 
       return {
         registerTable,
         registerChargeModal,
-        handleOpenChargeModal,
+        registerDeviceModal,
+        registerSubaccountModal,
+        handleOpenModal,
         uploadApi: uploadApi as any,
       };
     },

+ 23 - 20
src/views/sys/login/LoginForm.vue

@@ -25,7 +25,7 @@
       />
     </FormItem>
 
-    <!-- <ARow class="enter-x">
+    <ARow class="enter-x">
       <ACol :span="12">
         <FormItem name="captcha">
           <Input
@@ -39,16 +39,16 @@
       <ACol :span="12" :style="{ 'text-align': 'right' }">
         <img class="captcha-img" :src="`http://192.168.0.47:8190/captcha.jpg?t=${Date.now()}`" />
       </ACol>
-    </ARow> -->
+    </ARow>
 
-    <FormItem name="drag" class="enter-x" :style="{ 'text-align': 'right' }">
+    <!-- <FormItem name="drag" class="enter-x" :style="{ 'text-align': 'right' }">
       <BasicDragVerify
         ref="el3"
         @success="handleSuccess"
         text="拖动以进行校验"
         successText="校验成功"
       />
-    </FormItem>
+    </FormItem> -->
 
     <ARow class="enter-x">
       <ACol :span="12">
@@ -120,7 +120,7 @@
   // } from '@ant-design/icons-vue';
   import LoginFormTitle from './LoginFormTitle.vue';
 
-  import { BasicDragVerify } from '/@/components/Verify/index';
+  // import { BasicDragVerify } from '/@/components/Verify/index';
 
   import { useI18n } from '/@/hooks/web/useI18n';
   import { useMessage } from '/@/hooks/web/useMessage';
@@ -128,6 +128,7 @@
   import { useUserStore } from '/@/store/modules/user';
   import { LoginStateEnum, useLoginState, useFormRules, useFormValid } from './useLogin';
   import { useDesign } from '/@/hooks/web/useDesign';
+
   //import { onKeyStroke } from '@vueuse/core';
 
   const ACol = Col;
@@ -145,12 +146,13 @@
   const formRef = ref();
   const loading = ref(false);
   const rememberMe = ref(false);
-  const isDragValidate = ref(false);
+  // const isDragValidate = ref(false);
 
   const formData = reactive({
     account: '17324327132',
-    // password: 'zfb123456',
-    password: 'USFf52nBZiMTIzNDU2WAJ7GAofemSXnYdUok',
+    password: 'zfb123456',
+    // password: encodeStr(window.btoa('zfb123456')),
+    captcha: '',
   });
 
   const { validForm } = useFormValid(formRef);
@@ -159,27 +161,28 @@
 
   const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN);
 
-  function handleSuccess() {
-    // console.log('11');
-    isDragValidate.value = true;
-  }
+  // function handleSuccess() {
+  //   // console.log('11');
+  //   isDragValidate.value = true;
+  // }
 
   async function handleLogin() {
     const data = await validForm();
     if (!data) return;
-    if (!isDragValidate.value) {
-      notification.info({
-        message: t('sys.login.loginDragValidate'),
-        description: `${t('sys.login.loginAgain')}`,
-        duration: 3,
-      });
-      return;
-    }
+    // if (!isDragValidate.value) {
+    //   notification.info({
+    //     message: t('sys.login.loginDragValidate'),
+    //     description: `${t('sys.login.loginAgain')}`,
+    //     duration: 3,
+    //   });
+    //   return;
+    // }
     try {
       loading.value = true;
       const userInfo = await userStore.login({
         password: data.password,
         username: data.account,
+        captcha: data.captcha,
         mode: 'none', //不要默认的错误提示
       });
 

+ 13 - 4
types/axios.d.ts

@@ -25,11 +25,20 @@ export interface RequestOptions {
   withToken?: boolean;
 }
 
-export interface Result<T = any> {
+// export interface Result<T = any> {
+//   code: number;
+//   type: 'success' | 'error' | 'warning';
+//   message: string | T;
+//   result: T;
+// }
+export type Result = FlawResult;
+//TODO 后端不标准的返回字段
+export interface FlawResult<T = any> {
   code: number;
-  type: 'success' | 'error' | 'warning';
-  message: string | T;
-  result: T;
+  type?: 'success' | 'error' | 'warning';
+  message: T;
+  result?: T;
+  error?: string;
 }
 
 // multipart/form-data: upload file