Ver Fonte

fix:添加圈量配置文件及目录

jimmyyem há 1 dia atrás
pai
commit
191c0122bd

+ 26 - 0
src/api/wechat/model/xunjiModel.ts

@@ -0,0 +1,26 @@
+import { BaseListResp } from '@/api/model/baseModel';
+
+/**
+ *  @description: Xunji info response
+ */
+export interface XunjiInfo {
+  id?: number;
+  createdAt?: number;
+  updatedAt?: number;
+  status?: number;
+  appKey?: string;
+  appSecret?: string;
+  token?: string;
+  encodingKey?: string;
+  agentId?: number;
+  organizationId?: number;
+  wxid?: string;
+  apiBase?: string;
+  apiKey?: string;
+}
+
+/**
+ *  @description: Xunji list response
+ */
+
+export type XunjiListResp = BaseListResp<XunjiInfo>;

+ 74 - 0
src/api/wechat/xunji.ts

@@ -0,0 +1,74 @@
+import { defHttp } from '@/utils/http/axios';
+import { ErrorMessageMode } from '/#/axios';
+import { BaseDataResp, BaseListReq, BaseResp, BaseIDsReq, BaseIDReq } from '@/api/model/baseModel';
+import { XunjiInfo, XunjiListResp } from './model/xunjiModel';
+
+enum Api {
+  CreateXunji = '/wechat-api/xunji/create',
+  UpdateXunji = '/wechat-api/xunji/update',
+  GetXunjiList = '/wechat-api/xunji/list',
+  DeleteXunji = '/wechat-api/xunji/delete',
+  GetXunjiById = '/wechat-api/xunji',
+}
+
+/**
+ * @description: Get xunji list
+ */
+
+export const getXunjiList = (params: BaseListReq, mode: ErrorMessageMode = 'notice') => {
+  return defHttp.post<BaseDataResp<XunjiListResp>>(
+    { url: Api.GetXunjiList, params },
+    { errorMessageMode: mode },
+  );
+};
+
+/**
+ *  @description: Create a new xunji
+ */
+export const createXunji = (params: XunjiInfo, mode: ErrorMessageMode = 'notice') => {
+  return defHttp.post<BaseResp>(
+    { url: Api.CreateXunji, params: params },
+    {
+      errorMessageMode: mode,
+      successMessageMode: mode,
+    },
+  );
+};
+
+/**
+ *  @description: Update the xunji
+ */
+export const updateXunji = (params: XunjiInfo, mode: ErrorMessageMode = 'notice') => {
+  return defHttp.post<BaseResp>(
+    { url: Api.UpdateXunji, params: params },
+    {
+      errorMessageMode: mode,
+      successMessageMode: mode,
+    },
+  );
+};
+
+/**
+ *  @description: Delete xunjis
+ */
+export const deleteXunji = (params: BaseIDsReq, mode: ErrorMessageMode = 'notice') => {
+  return defHttp.post<BaseResp>(
+    { url: Api.DeleteXunji, params: params },
+    {
+      errorMessageMode: mode,
+      successMessageMode: mode,
+    },
+  );
+};
+
+/**
+ *  @description: Get xunji By ID
+ */
+export const getXunjiById = (params: BaseIDReq, mode: ErrorMessageMode = 'notice') => {
+  return defHttp.post<BaseDataResp<XunjiInfo>>(
+    { url: Api.GetXunjiById, params: params },
+    {
+      errorMessageMode: mode,
+    },
+  );
+};

+ 15 - 0
src/locales/lang/en/wechat.ts

@@ -293,4 +293,19 @@ export default {
     editCreditBalance: 'Edit Balance',
     creditBalanceList: 'Balance List',
   },
+  xunji: {
+    status: 'Status',
+    appKey: 'AppKey',
+    appSecret: 'AppSecret',
+    token: 'Token',
+    encodingKey: 'EncodingKey',
+    agentId: 'AgentId',
+    organizationId: 'OrganizationId',
+    wxid: 'Wxid',
+    apiBase: 'ApiBase',
+    apiKey: 'ApiKey',
+    addXunji: 'Add Xunji',
+    editXunji: 'Edit Xunji',
+    xunjiList: 'Xunji List',
+  },
 };

+ 15 - 0
src/locales/lang/zh-CN/wechat.ts

@@ -307,4 +307,19 @@ export default {
     editCreditBalance: '编辑余额',
     creditBalanceList: '余额列表',
   },
+  xunji: {
+    status: 'Status',
+    appKey: 'AppKey',
+    appSecret: 'AppSecret',
+    token: 'Token',
+    encodingKey: 'EncodingKey',
+    agentId: 'AgentId',
+    organizationId: 'OrganizationId',
+    wxid: 'Wxid',
+    apiBase: 'ApiBase',
+    apiKey: 'ApiKey',
+    addXunji: '添加 Xunji',
+    editXunji: '编辑 Xunji',
+    xunjiList: 'Xunji 列表',
+  },
 };

+ 75 - 0
src/views/wechat/xunji/XunjiDrawer.vue

@@ -0,0 +1,75 @@
+<template>
+  <BasicDrawer
+    v-bind="$attrs"
+    @register="registerDrawer"
+    showFooter
+    :title="getTitle"
+    width="35%"
+    @ok="handleSubmit"
+  >
+    <BasicForm @register="registerForm" />
+  </BasicDrawer>
+</template>
+<script lang="ts">
+  import { defineComponent, ref, computed, unref } from 'vue';
+  import { BasicForm, useForm } from '@/components/Form/index';
+  import { formSchema } from './xunji.data';
+  import { BasicDrawer, useDrawerInner } from '@/components/Drawer';
+  import { useI18n } from 'vue-i18n';
+
+  import { createXunji, updateXunji } from '@/api/wechat/xunji';
+
+  export default defineComponent({
+    name: 'XunjiDrawer',
+    components: { BasicDrawer, BasicForm },
+    emits: ['success', 'register'],
+    setup(_, { emit }) {
+      const isUpdate = ref(true);
+      const { t } = useI18n();
+
+      const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({
+        labelWidth: 160,
+        baseColProps: { span: 24 },
+        layout: 'vertical',
+        schemas: formSchema,
+        showActionButtonGroup: false,
+      });
+
+      const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
+        resetFields();
+        setDrawerProps({ confirmLoading: false });
+
+        isUpdate.value = !!data?.isUpdate;
+
+        if (unref(isUpdate)) {
+          setFieldsValue({
+            ...data.record,
+          });
+        }
+      });
+
+      const getTitle = computed(() =>
+        !unref(isUpdate) ? t('wechat.xunji.addXunji') : t('wechat.xunji.editXunji'),
+      );
+
+      async function handleSubmit() {
+        const values = await validate();
+        setDrawerProps({ confirmLoading: true });
+        values['id'] = unref(isUpdate) ? Number(values['id']) : 0;
+        let result = unref(isUpdate) ? await updateXunji(values) : await createXunji(values);
+        if (result.code === 0) {
+          closeDrawer();
+          emit('success');
+        }
+        setDrawerProps({ confirmLoading: false });
+      }
+
+      return {
+        registerDrawer,
+        registerForm,
+        getTitle,
+        handleSubmit,
+      };
+    },
+  });
+</script>

+ 152 - 0
src/views/wechat/xunji/index.vue

@@ -0,0 +1,152 @@
+<template>
+  <div>
+    <BasicTable @register="registerTable">
+      <template #tableTitle>
+        <Button
+          type="primary"
+          danger
+          preIcon="ant-design:delete-outlined"
+          v-if="showDeleteButton"
+          @click="handleBatchDelete"
+        >
+          {{ t('common.delete') }}
+        </Button>
+      </template>
+      <template #toolbar>
+        <a-button type="primary" @click="handleCreate">
+          {{ t('wechat.xunji.addXunji') }}
+        </a-button>
+      </template>
+      <template #bodyCell="{ column, record }">
+        <template v-if="column.key === 'action'">
+          <TableAction
+            :actions="[
+              {
+                icon: 'clarity:note-edit-line',
+                onClick: handleEdit.bind(null, record),
+              },
+              {
+                icon: 'ant-design:delete-outlined',
+                color: 'error',
+                popConfirm: {
+                  title: t('common.deleteConfirm'),
+                  placement: 'left',
+                  confirm: handleDelete.bind(null, record),
+                },
+              },
+            ]"
+          />
+        </template>
+      </template>
+    </BasicTable>
+    <XunjiDrawer @register="registerDrawer" @success="handleSuccess" />
+  </div>
+</template>
+<script lang="ts">
+  import { createVNode, defineComponent, ref } from 'vue';
+  import { Modal } from 'ant-design-vue';
+  import { ExclamationCircleOutlined } from '@ant-design/icons-vue/lib/icons';
+  import { BasicTable, useTable, TableAction } from '@/components/Table';
+  import { Button } from '@/components/Button';
+
+  import { useDrawer } from '@/components/Drawer';
+  import XunjiDrawer from './XunjiDrawer.vue';
+  import { useI18n } from 'vue-i18n';
+
+  import { columns, searchFormSchema } from './xunji.data';
+  import { getXunjiList, deleteXunji } from '@/api/wechat/xunji';
+
+  export default defineComponent({
+    name: 'XunjiManagement',
+    components: { BasicTable, XunjiDrawer, TableAction, Button },
+    setup() {
+      const { t } = useI18n();
+      const selectedIds = ref<number[] | string[]>();
+      const showDeleteButton = ref<boolean>(false);
+
+      const [registerDrawer, { openDrawer }] = useDrawer();
+      const [registerTable, { reload }] = useTable({
+        title: t('wechat.xunji.xunjiList'),
+        api: getXunjiList,
+        columns,
+        formConfig: {
+          labelWidth: 120,
+          schemas: searchFormSchema,
+        },
+        useSearchForm: true,
+        showTableSetting: true,
+        bordered: true,
+        showIndexColumn: false,
+        clickToRowSelect: false,
+        actionColumn: {
+          width: 30,
+          title: t('common.action'),
+          dataIndex: 'action',
+          fixed: undefined,
+        },
+        rowKey: 'id',
+        rowSelection: {
+          type: 'checkbox',
+          columnWidth: 20,
+          onChange: (selectedRowKeys, _selectedRows) => {
+            selectedIds.value = selectedRowKeys as number[];
+            showDeleteButton.value = selectedRowKeys.length > 0;
+          },
+        },
+      });
+
+      function handleCreate() {
+        openDrawer(true, {
+          isUpdate: false,
+        });
+      }
+
+      function handleEdit(record: Recordable) {
+        openDrawer(true, {
+          record,
+          isUpdate: true,
+        });
+      }
+
+      async function handleDelete(record: Recordable) {
+        const result = await deleteXunji({ ids: [record.id] });
+        if (result.code === 0) {
+          await reload();
+        }
+      }
+
+      async function handleBatchDelete() {
+        Modal.confirm({
+          title: t('common.deleteConfirm'),
+          icon: createVNode(ExclamationCircleOutlined),
+          async onOk() {
+            const result = await deleteXunji({ ids: selectedIds.value as number[] });
+            if (result.code === 0) {
+              showDeleteButton.value = false;
+              await reload();
+            }
+          },
+          onCancel() {
+            console.log('Cancel');
+          },
+        });
+      }
+
+      async function handleSuccess() {
+        await reload();
+      }
+
+      return {
+        t,
+        registerTable,
+        registerDrawer,
+        handleCreate,
+        handleEdit,
+        handleDelete,
+        handleSuccess,
+        handleBatchDelete,
+        showDeleteButton,
+      };
+    },
+  });
+</script>

+ 187 - 0
src/views/wechat/xunji/xunji.data.ts

@@ -0,0 +1,187 @@
+import { BasicColumn, FormSchema } from '@/components/Table';
+import { useI18n } from '@/hooks/web/useI18n';
+import { formatToDateTime } from '@/utils/dateUtil';
+import { updateXunji } from '@/api/wechat/xunji';
+import { Switch } from 'ant-design-vue';
+import { h } from 'vue';
+
+const { t } = useI18n();
+
+export const columns: BasicColumn[] = [
+  {
+    title: t('wechat.xunji.appKey'),
+    dataIndex: 'appKey',
+    width: 100,
+  },
+  {
+    title: t('wechat.xunji.appSecret'),
+    dataIndex: 'appSecret',
+    width: 100,
+  },
+  {
+    title: t('wechat.xunji.token'),
+    dataIndex: 'token',
+    width: 100,
+  },
+  {
+    title: t('wechat.xunji.encodingKey'),
+    dataIndex: 'encodingKey',
+    width: 100,
+  },
+  {
+    title: t('wechat.xunji.agentId'),
+    dataIndex: 'agentId',
+    width: 100,
+  },
+  {
+    title: t('wechat.xunji.organizationId'),
+    dataIndex: 'organizationId',
+    width: 100,
+  },
+  {
+    title: t('wechat.xunji.wxid'),
+    dataIndex: 'wxid',
+    width: 100,
+  },
+  {
+    title: t('wechat.xunji.apiBase'),
+    dataIndex: 'apiBase',
+    width: 100,
+  },
+  {
+    title: t('wechat.xunji.apiKey'),
+    dataIndex: 'apiKey',
+    width: 100,
+  },
+  {
+    title: t('common.status'),
+    dataIndex: 'status',
+    width: 50,
+    customRender: ({ record }) => {
+      if (!Reflect.has(record, 'pendingStatus')) {
+        record.pendingStatus = false;
+      }
+      return h(Switch, {
+        checked: record.status === 1,
+        checkedChildren: t('common.on'),
+        unCheckedChildren: t('common.off'),
+        loading: record.pendingStatus,
+        onChange(checked, _) {
+          record.pendingStatus = true;
+          const newStatus = checked ? 1 : 2;
+          updateXunji({ id: record.id, status: newStatus })
+            .then(() => {
+              record.status = newStatus;
+            })
+            .finally(() => {
+              record.pendingStatus = false;
+            });
+        },
+      });
+    },
+  },
+  {
+    title: t('common.createTime'),
+    dataIndex: 'createdAt',
+    width: 70,
+    customRender: ({ record }) => {
+      return formatToDateTime(record.createdAt);
+    },
+  },
+];
+
+export const searchFormSchema: FormSchema[] = [
+  {
+    field: 'appKey',
+    label: t('wechat.xunji.appKey'),
+    component: 'Input',
+    colProps: { span: 8 },
+  },
+  {
+    field: 'appSecret',
+    label: t('wechat.xunji.appSecret'),
+    component: 'Input',
+    colProps: { span: 8 },
+  },
+  {
+    field: 'token',
+    label: t('wechat.xunji.token'),
+    component: 'Input',
+    colProps: { span: 8 },
+  },
+];
+
+export const formSchema: FormSchema[] = [
+  {
+    field: 'id',
+    label: 'ID',
+    component: 'Input',
+    show: false,
+  },
+  {
+    field: 'appKey',
+    label: t('wechat.xunji.appKey'),
+    component: 'Input',
+    required: true,
+  },
+  {
+    field: 'appSecret',
+    label: t('wechat.xunji.appSecret'),
+    component: 'Input',
+    required: true,
+  },
+  {
+    field: 'token',
+    label: t('wechat.xunji.token'),
+    component: 'Input',
+    required: true,
+  },
+  {
+    field: 'encodingKey',
+    label: t('wechat.xunji.encodingKey'),
+    component: 'Input',
+    required: true,
+  },
+  {
+    field: 'agentId',
+    label: t('wechat.xunji.agentId'),
+    component: 'InputNumber',
+    required: true,
+  },
+  {
+    field: 'organizationId',
+    label: t('wechat.xunji.organizationId'),
+    component: 'InputNumber',
+    required: true,
+  },
+  {
+    field: 'wxid',
+    label: t('wechat.xunji.wxid'),
+    component: 'Input',
+    required: true,
+  },
+  {
+    field: 'apiBase',
+    label: t('wechat.xunji.apiBase'),
+    component: 'Input',
+    required: true,
+  },
+  {
+    field: 'apiKey',
+    label: t('wechat.xunji.apiKey'),
+    component: 'Input',
+    required: true,
+  },
+  {
+    field: 'status',
+    label: t('wechat.xunji.status'),
+    component: 'RadioButtonGroup',
+    defaultValue: 1,
+    componentProps: {
+      options: [
+        { label: t('common.on'), value: 1 },
+        { label: t('common.off'), value: 2 },
+      ],
+    },
+  },
+];