Browse Source

Merge branch 'dev' of http://git.ascrm.cn:3000/scrm/wechat-ui into dev

luzhenxing 3 months ago
parent
commit
86b28a09fc

+ 74 - 0
src/api/wechat/labelTagging.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 { LabelTaggingInfo, LabelTaggingListResp } from './model/labelTaggingModel';
+
+enum Api {
+  CreateLabelTagging = '/wechat-api/label_tagging/create',
+  UpdateLabelTagging = '/wechat-api/label_tagging/update',
+  GetLabelTaggingList = '/wechat-api/label_tagging/list',
+  DeleteLabelTagging = '/wechat-api/label_tagging/delete',
+  GetLabelTaggingById = '/wechat-api/label_tagging',
+}
+
+/**
+ * @description: Get label tagging list
+ */
+
+export const getLabelTaggingList = (params: BaseListReq, mode: ErrorMessageMode = 'notice') => {
+  return defHttp.post<BaseDataResp<LabelTaggingListResp>>(
+    { url: Api.GetLabelTaggingList, params },
+    { errorMessageMode: mode },
+  );
+};
+
+/**
+ *  @description: Create a new label tagging
+ */
+export const createLabelTagging = (params: LabelTaggingInfo, mode: ErrorMessageMode = 'notice') => {
+  return defHttp.post<BaseResp>(
+    { url: Api.CreateLabelTagging, params: params },
+    {
+      errorMessageMode: mode,
+      successMessageMode: mode,
+    },
+  );
+};
+
+/**
+ *  @description: Update the label tagging
+ */
+export const updateLabelTagging = (params: LabelTaggingInfo, mode: ErrorMessageMode = 'notice') => {
+  return defHttp.post<BaseResp>(
+    { url: Api.UpdateLabelTagging, params: params },
+    {
+      errorMessageMode: mode,
+      successMessageMode: mode,
+    },
+  );
+};
+
+/**
+ *  @description: Delete label taggings
+ */
+export const deleteLabelTagging = (params: BaseIDsReq, mode: ErrorMessageMode = 'notice') => {
+  return defHttp.post<BaseResp>(
+    { url: Api.DeleteLabelTagging, params: params },
+    {
+      errorMessageMode: mode,
+      successMessageMode: mode,
+    },
+  );
+};
+
+/**
+ *  @description: Get label tagging By ID
+ */
+export const getLabelTaggingById = (params: BaseIDReq, mode: ErrorMessageMode = 'notice') => {
+  return defHttp.post<BaseDataResp<LabelTaggingInfo>>(
+    { url: Api.GetLabelTaggingById, params: params },
+    {
+      errorMessageMode: mode,
+    },
+  );
+};

+ 22 - 0
src/api/wechat/model/labelTaggingModel.ts

@@ -0,0 +1,22 @@
+import { BaseListResp } from '@/api/model/baseModel';
+
+/**
+ *  @description: LabelTagging info response
+ */
+export interface LabelTaggingInfo {
+  id?: number;
+  createdAt?: number;
+  updatedAt?: number;
+  status?: number;
+  organizationId?: number;
+  type?: number;
+  conditions?: string;
+  actionLabelAdd?: number[];
+  actionLabelDel?: number[];
+}
+
+/**
+ *  @description: LabelTagging list response
+ */
+
+export type LabelTaggingListResp = BaseListResp<LabelTaggingInfo>;

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

@@ -241,4 +241,15 @@ export default {
     editDashboard: 'Edit Dashboard',
     dashboardList: 'Dashboard List',
   },
+  labelTagging: {
+    status: 'Status',
+    organizationId: 'OrganizationId',
+    type: 'Type',
+    conditions: 'Conditions',
+    actionLabelAdd: 'ActionLabelAdd',
+    actionLabelDel: 'ActionLabelDel',
+    addLabelTagging: 'Add LabelTagging',
+    editLabelTagging: 'Edit LabelTagging',
+    labelTaggingList: 'LabelTagging List',
+  },
 };

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

@@ -253,4 +253,15 @@ export default {
     editDashboard: '编辑 Dashboard',
     dashboardList: 'Dashboard 列表',
   },
+  labelTagging: {
+    status: 'Status',
+    organizationId: 'OrganizationId',
+    type: 'Type',
+    conditions: 'Conditions',
+    actionLabelAdd: 'ActionLabelAdd',
+    actionLabelDel: 'ActionLabelDel',
+    addLabelTagging: '添加 LabelTagging',
+    editLabelTagging: '编辑 LabelTagging',
+    labelTaggingList: 'LabelTagging 列表',
+  },
 };

+ 62 - 0
src/views/wechat/label_tagging/LabelTaggingDrawer.vue

@@ -0,0 +1,62 @@
+<template>
+  <BasicDrawer
+    v-bind="$attrs"
+    @register="registerDrawer"
+    showFooter
+    :title="getTitle"
+    width="35%"
+    @ok="handleSubmit"
+  >
+    <BasicForm @register="registerForm" />
+  </BasicDrawer>
+</template>
+<script lang="ts" setup>
+  import { ref, computed, unref } from 'vue';
+  import { BasicForm, useForm } from '@/components/Form/index';
+  import { formSchema } from './labelTagging.data';
+  import { BasicDrawer, useDrawerInner } from '@/components/Drawer';
+  import { useI18n } from 'vue-i18n';
+
+  import { createLabelTagging, updateLabelTagging } from '@/api/wechat/labelTagging';
+
+  const emit = defineEmits(['success', 'register']);
+  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) => {
+    await resetFields();
+    setDrawerProps({ confirmLoading: false });
+
+    isUpdate.value = !!data?.isUpdate;
+
+    if (unref(isUpdate)) {
+      await setFieldsValue({
+        ...data.record,
+      });
+    }
+  });
+
+  const getTitle = computed(() =>
+    !unref(isUpdate) ? t('wechat.labelTagging.addLabelTagging') : t('wechat.labelTagging.editLabelTagging'),
+  );
+
+  async function handleSubmit() {
+    const values = await validate();
+    setDrawerProps({ confirmLoading: true });
+    values['id'] = unref(isUpdate) ? Number(values['id']) : 0;
+    let result = unref(isUpdate) ? await updateLabelTagging(values) : await createLabelTagging(values);
+    if (result.code === 0) {
+      closeDrawer();
+      emit('success');
+    }
+    setDrawerProps({ confirmLoading: false });
+  }
+</script>

+ 136 - 0
src/views/wechat/label_tagging/index.vue

@@ -0,0 +1,136 @@
+<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.labelTagging.addLabelTagging') }}
+        </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>
+    <LabelTaggingDrawer @register="registerDrawer" @success="handleSuccess" />
+  </div>
+</template>
+<script lang="ts" setup>
+  import { createVNode, 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 LabelTaggingDrawer from './LabelTaggingDrawer.vue';
+  import { useI18n } from 'vue-i18n';
+
+  import { columns, searchFormSchema } from './labelTagging.data';
+  import { getLabelTaggingList, deleteLabelTagging } from '@/api/wechat/labelTagging';
+
+  defineOptions({ name: 'LabelTaggingManagement' });
+
+  const { t } = useI18n();
+  const selectedIds = ref<number[] | string[]>();
+  const showDeleteButton = ref<boolean>(false);
+
+  const [registerDrawer, { openDrawer }] = useDrawer();
+  const [registerTable, { reload }] = useTable({
+    title: t('wechat.labelTagging.labelTaggingList'),
+    api: getLabelTaggingList,
+    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 deleteLabelTagging({ 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 deleteLabelTagging({ ids: selectedIds.value as number[] });
+        if (result.code === 0) {
+          showDeleteButton.value = false;
+          await reload();
+        }
+      },
+      onCancel() {
+        console.log('Cancel');
+      },
+    });
+  }
+
+  async function handleSuccess() {
+    await reload();
+  }
+</script>

+ 125 - 0
src/views/wechat/label_tagging/labelTagging.data.ts

@@ -0,0 +1,125 @@
+import { BasicColumn, FormSchema } from '@/components/Table';
+import { useI18n } from '@/hooks/web/useI18n';
+import { formatToDateTime } from '@/utils/dateUtil';
+import { updateLabelTagging } from '@/api/wechat/labelTagging';
+import { Switch } from 'ant-design-vue';
+import { h } from 'vue';
+
+const { t } = useI18n();
+
+export const columns: BasicColumn[] = [
+  {
+    title: t('wechat.labelTagging.organizationId'),
+    dataIndex: 'organizationId',
+    width: 100,
+  },
+  {
+    title: t('wechat.labelTagging.type'),
+    dataIndex: 'type',
+    width: 100,
+  },
+  {
+    title: t('wechat.labelTagging.conditions'),
+    dataIndex: 'conditions',
+    width: 100,
+  },
+  {
+    title: t('wechat.labelTagging.actionLabelAdd'),
+    dataIndex: 'actionLabelAdd',
+    width: 100,
+  },
+  {
+    title: t('wechat.labelTagging.actionLabelDel'),
+    dataIndex: 'actionLabelDel',
+    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;
+          updateLabelTagging({ 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[] = [
+];
+
+export const formSchema: FormSchema[] = [
+  {
+    field: 'id',
+    label: 'ID',
+    component: 'Input',
+    show: false,
+  },
+  {
+    field: 'organizationId',
+    label: t('wechat.labelTagging.organizationId'),
+    component: 'InputNumber',
+    required: true,
+  },
+  {
+    field: 'type',
+    label: t('wechat.labelTagging.type'),
+    component: 'InputNumber',
+    required: true,
+  },
+  {
+    field: 'conditions',
+    label: t('wechat.labelTagging.conditions'),
+    component: 'Input',
+    required: true,
+  },
+  {
+    field: 'actionLabelAdd',
+    label: t('wechat.labelTagging.actionLabelAdd'),
+    component: 'Input',
+    required: true,
+  },
+  {
+    field: 'actionLabelDel',
+    label: t('wechat.labelTagging.actionLabelDel'),
+    component: 'Input',
+    required: true,
+  },
+  {
+    field: 'status',
+    label: t('wechat.labelTagging.status'),
+    component: 'RadioButtonGroup',
+    defaultValue: 1,
+    componentProps: {
+      options: [
+        { label: t('common.on'), value: 1 },
+        { label: t('common.off'), value: 2 },
+      ],
+    },
+  },
+];