luzhenxing 2 luni în urmă
părinte
comite
3de9d79147

+ 4 - 2
src/api/wechat/agent.ts

@@ -14,8 +14,10 @@ enum Api {
 /**
  * @description: Get agent list
  */
-
-export const getAgentList = (params: BaseListReq, mode: ErrorMessageMode = 'notice') => {
+interface AgentListReq extends BaseListReq {
+  organizationId: number
+}
+export const getAgentList = (params: AgentListReq, mode: ErrorMessageMode = 'notice') => {
   return defHttp.post<BaseDataResp<AgentListResp>>(
     { url: Api.GetAgentList, params },
     { errorMessageMode: mode },

+ 4 - 1
src/api/wechat/gpts.ts

@@ -17,6 +17,9 @@ export const getAllocAgent = (params: AllocReq, mode: ErrorMessageMode = 'notice
 export const postAllocAgent = (params: AllocReq, mode: ErrorMessageMode = 'notice') => {
   return defHttp.post<BaseDataResp<null>>(
     { url: Api.PostAllocAgent, params },
-    { errorMessageMode: mode },
+    {
+      successMessageMode: mode,
+      errorMessageMode: mode
+    },
   );
 };

+ 1 - 0
src/api/wechat/model/tokenModel.ts

@@ -11,6 +11,7 @@ export interface TokenInfo {
   expireAtStr?: string;
   token?: string;
   mac?: string;
+  agent_id?: number;
 }
 
 /**

+ 58 - 0
src/views/components/ SelectAIAgentModal.vue

@@ -0,0 +1,58 @@
+<template>
+  <BasicModal
+    title="选择AI角色"
+    :canFullscreen="false"
+    v-bind="$attrs"
+    okText="保存"
+    @register="registerModal"
+    @ok="handleOk"
+  >
+    <Form :model="form" layout="inline" style="height: 200px">
+      <FormItem name="name" label="选择模式" style="margin-left: 30px">
+        <Select
+          v-model:value="form.id"
+          :options="modeList"
+          allowClear
+          size="middle"
+          placeholder="请选择"
+          :style="{ width: '330px', margin: '0 5px' }"
+        ></Select>
+      </FormItem>
+    </Form>
+  </BasicModal>
+</template>
+<script lang="ts" setup>
+import { ref, reactive } from 'vue';
+import { BasicModal, useModalInner } from '/@/components/Modal'
+import { Form, FormItem, Select } from 'ant-design-vue';
+import { getAgentList } from '/@/api/wechat/agent';
+import { DefaultOptionType } from 'ant-design-vue/es/select';
+import { updateWx } from '/@/api/wechat/wx';
+
+const modeList = ref<DefaultOptionType[]>([])
+const form = reactive({
+  name: '',
+  id: undefined,
+});
+const accountId = ref()
+const emit = defineEmits(['ok']);
+
+const [registerModal, { closeModal }] = useModalInner(async ({ id, name, organizationId, accountId: aId }) => {
+  accountId.value = aId
+  form.id = id
+  form.name = name
+  const res = await getAgentList({
+    page: 1,
+    pageSize: 1000,
+    organizationId
+  })
+  modeList.value = res.data.data.map((item: any) => ({
+    label: item.name, // 确保使用 label 和 value
+    value: item.id,
+  }));
+  modeList.value.unshift({ label: '定制 AI 角色', value: 0 });
+})
+async function handleOk() {
+  emit('ok', { agentId: form.id, id: accountId.value })
+}
+</script>

+ 14 - 7
src/views/components/AllocAgentsModal.vue

@@ -54,8 +54,9 @@ import { useI18n } from '@/hooks/web/useI18n';
 import { formatToDateTime } from '@/utils/dateUtil';
 
 const { t } = useI18n();
-const targetKeys = ref([])
-const selectedKeys = ref([])
+const emit = defineEmits(['ok']);
+const targetKeys = ref<string[]>([])
+const selectedKeys = ref<string[]>([])
 
 const employeeData = ref()
 const leftColumns = [{
@@ -79,16 +80,18 @@ const rightColumns = [{
   title: t('wechat.employee.title'),
   dataIndex: 'title',
 }]
+
+const agentParams = ref()
 onMounted(async () => {
   const res = await getEmployeeList({ page: 1, pageSize: 1000 })
   employeeData.value = res.data.data.map(o => Object.assign({ key: `${o.id}` }, o))
   // targetKeys.value = res.data.data.map(o => o.id)
 })
-const [registerModal] = useModalInner(async (params) => {
+const [registerModal, { closeModal }] = useModalInner(async (params) => {
+  agentParams.value = params
   const res = await getAllocAgent(params)
-  console.log(res)
   selectedKeys.value = []
-  targetKeys.value = []
+  targetKeys.value = res.data.agents ? res.data.agents.map(o => o.toString()) : []
 })
 
 const getRowSelection = ({
@@ -107,8 +110,12 @@ const getRowSelection = ({
     selectedRowKeys: selectedKeys,
   };
 };
-function handleSubmit() {
-  console.log(targetKeys.value)
+async function handleSubmit() {
+  try {
+    await postAllocAgent(Object.assign({ agents: targetKeys.value }, agentParams.value))
+  } finally {
+    closeModal()
+  }
 }
 </script>
 <style lang="scss" scoped>

+ 101 - 115
src/views/wechat/token/index.vue

@@ -46,133 +46,119 @@
       </template>
     </BasicTable>
     <TokenDrawer @register="registerDrawer" @success="handleSuccess" />
-    <ModeDrawer @register="registerModeDrawer" @success="handleSuccess" />
+    <SelectAIAgentModal @register="registerAIAgentModal" @ok="handleUpdateAgent" />
   </div>
 </template>
-<script lang="ts">
-import {createVNode, defineComponent, onMounted, ref} from 'vue';
-  import {Form, FormItem, message, Modal, Select} 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';
+<script lang="ts" setup>
+import {createVNode, onMounted, 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 TokenDrawer from './TokenDrawer.vue';
-  import ModeDrawer from './ModeDrawer.vue';
-  import { useI18n } from 'vue-i18n';
+import { useDrawer } from '@/components/Drawer';
+import TokenDrawer from './TokenDrawer.vue';
+import { useI18n } from 'vue-i18n';
 
-  import { columns, searchFormSchema } from './token.data';
-  import { getTokenList, deleteToken } from '@/api/wechat/token';
-  import {updateWx} from "@/api/wechat/wx";
-  import { getPermCode } from '@/api/sys/user';
-  import {getAgentList} from "@/api/wechat/agent";
-  import {getServerList} from "@/api/wechat/server";
-  let permCode = ref('');
-  export default defineComponent({
-    name: 'TokenManagement',
-    components: {Modal, Select, FormItem, Form, BasicTable, TokenDrawer, ModeDrawer, TableAction, Button },
-    setup() {
-      const { t } = useI18n();
-      const selectedIds = ref<number[] | string[]>();
-      const showDeleteButton = ref<boolean>(false);
-      const [registerDrawer, { openDrawer }] = useDrawer();
-      const [registerModeDrawer, { openDrawer: openModeDrawer }] = useDrawer();
-      const [registerTable, { reload }] = useTable({
-        title: t('wechat.token.tokenList'),
-        api: getTokenList,
-        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;
-          },
-        },
-      });
-
-      onMounted(async () => {
-        let res = await getPermCode();
-        permCode.value = res.data[0];
-      });
+import { columns, searchFormSchema } from './token.data';
+import { getTokenList, deleteToken, updateToken } from '@/api/wechat/token';
+import { getPermCode } from '@/api/sys/user';
+import SelectAIAgentModal from '@/views/components/ SelectAIAgentModal.vue';
+import { useModal } from '/@/components/Modal';
+let permCode = ref('');
+const { t } = useI18n();
+const selectedIds = ref<number[] | string[]>();
+const showDeleteButton = ref<boolean>(false);
+const [registerDrawer, { openDrawer }] = useDrawer();
+const [registerAIAgentModal, { openModal: openAIAgentModal, closeModal: closeAIAgentModal }] = useModal();
+const [registerTable, { reload }] = useTable({
+  title: t('wechat.token.tokenList'),
+  api: getTokenList,
+  columns,
+  formConfig: {
+    labelWidth: 120,
+    schemas: searchFormSchema,
+  },
+  useSearchForm: true,
+  showTableSetting: true,
+  bordered: true,
+  showIndexColumn: false,
+  clickToRowSelect: false,
+  actionColumn: {
+    width: 80,
+    title: t('common.action'),
+    dataIndex: 'action'
+  },
+  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,
-        });
-      }
+onMounted(async () => {
+  let res = await getPermCode();
+  permCode.value = res.data[0];
+});
 
-      function handleEdit(record: Recordable) {
-        openDrawer(true, {
-          record,
-          isUpdate: true,
-        });
-      }
+function handleCreate() {
+  openDrawer(true, {
+    isUpdate: false,
+  });
+}
 
-      function handleEditMode(record: Recordable) {
-        openModeDrawer(true, {
-          record,
-        });
-      }
+function handleEdit(record: Recordable) {
+  openDrawer(true, {
+    record,
+    isUpdate: true,
+  });
+}
 
-      async function handleDelete(record: Recordable) {
-        const result = await deleteToken({ ids: [record.id] });
-        if (result.code === 0) {
-          await reload();
-        }
-      }
+function handleEditMode(record: Recordable) {
+  const name = record.agent_info?.name == null ? '定制 AI 角色' : record.agent_info?.name;
+  const id = record.agent_info?.id == null ? 0 : record.agent_info?.id;
+  openAIAgentModal(true, {
+    accountId: record.id,
+    name,
+    id,
+    organizationId: record.organization_id
+  });
+}
 
-      async function handleBatchDelete() {
-        Modal.confirm({
-          title: t('common.deleteConfirm'),
-          icon: createVNode(ExclamationCircleOutlined),
-          async onOk() {
-            const result = await deleteToken({ ids: selectedIds.value as number[] });
-            if (result.code === 0) {
-              showDeleteButton.value = false;
-              await reload();
-            }
-          },
-          onCancel() {
-            console.log('Cancel');
-          },
-        });
-      }
+async function handleDelete(record: Recordable) {
+  const result = await deleteToken({ ids: [record.id] });
+  if (result.code === 0) {
+    await reload();
+  }
+}
 
-      async function handleSuccess() {
+async function handleBatchDelete() {
+  Modal.confirm({
+    title: t('common.deleteConfirm'),
+    icon: createVNode(ExclamationCircleOutlined),
+    async onOk() {
+      const result = await deleteToken({ ids: selectedIds.value as number[] });
+      if (result.code === 0) {
+        showDeleteButton.value = false;
         await reload();
       }
-
-      return {
-        t,
-        registerTable,
-        registerDrawer,
-        registerModeDrawer,
-        handleCreate,
-        handleEdit,
-        handleEditMode,
-        handleDelete,
-        handleSuccess,
-        handleBatchDelete,
-        showDeleteButton,
-        permCode,
-      };
+    },
+    onCancel() {
+      console.log('Cancel');
     },
   });
+}
+
+async function handleSuccess() {
+  await reload();
+}
+async function handleUpdateAgent({id, agentId: agent_id }) {
+  await updateToken({ id, agent_id });
+  closeAIAgentModal();
+  reload()
+}
 </script>

+ 25 - 69
src/views/wechat/wx/index.vue

@@ -31,29 +31,7 @@
         <div v-html="modalContent"></div>
       </div>
     </BasicModal>
-    <WxDrawer @register="registerDrawer" @success="handleSuccess" />
-    <Modal
-      width="500px"
-      height="300px"
-      v-model:open="modalVisible"
-      title="选择 AI 角色"
-      @ok="handleOk"
-      @cancel="handleCancel"
-      class="custom-modal"
-    >
-      <Form :model="form" layout="inline" style="height: 200px">
-        <FormItem name="name" label="选择模式" style="margin-left: 30px">
-          <Select
-            v-model:value="form.id"
-            :options="modeList"
-            allowClear
-            size="middle"
-            placeholder="请选择"
-            :style="{ width: '330px', margin: '0 5px' }"
-          ></Select>
-        </FormItem>
-      </Form>
-    </Modal>
+    <WxDrawer @register="registerDrawer" @success="reload" />
     <!-- 编辑黑白名单 -->
     <Modal
       width="700px"
@@ -71,11 +49,11 @@
           />
           <div
             v-if="blackWhiteForm.isAllowListEnabled"
-            style="foon-size: 12px; margin-top: 10px; color: #9a9a9a"
+            style="margin-top: 10px; color: #9a9a9a; font-size: 12px;"
           >
             开启白名单表示仅向白名单内的客户发送消息
           </div>
-          <div v-else style="foon-size: 12px; margin-top: 10px; color: #9a9a9a">
+          <div v-else style="margin-top: 10px; color: #9a9a9a; font-size: 12px;">
             关闭白名单表示允许向所有客户发送消息
           </div>
           <FormItem v-if="blackWhiteForm.isAllowListEnabled" name="nickname" label="">
@@ -110,11 +88,11 @@
           <Switch v-model:checked="blackWhiteForm.isGroupAllowListEnabled" />
           <div
             v-if="blackWhiteForm.isGroupAllowListEnabled"
-            style="foon-size: 12px; margin-top: 10px; color: #9a9a9a"
+            style="margin-top: 10px; color: #9a9a9a; font-size: 12px;"
           >
             开启白名单表示仅向白名单内的客群发送消息
           </div>
-          <div v-else style="foon-size: 12px; margin-top: 10px; color: #9a9a9a">
+          <div v-else style="margin-top: 10px; color: #9a9a9a; font-size: 12px;">
             关闭白名单表示允许向所有客群发送消息
           </div>
           <FormItem v-if="blackWhiteForm.isGroupAllowListEnabled" name="nickname" label="">
@@ -138,11 +116,11 @@
           <Switch v-model:checked="blackWhiteForm.isBlockListEnabledt" />
           <div
             v-if="blackWhiteForm.isBlockListEnabledt"
-            style="foon-size: 12px; margin-top: 10px; color: #9a9a9a"
+            style="margin-top: 10px; color: #9a9a9a; font-size: 12px;"
           >
             黑名单优先级高于白名单
           </div>
-          <div v-else style="foon-size: 12px; margin-top: 10px; color: #9a9a9a">
+          <div v-else style="margin-top: 10px; color: #9a9a9a; font-size: 12px;">
             关闭黑名单表示允许向所有客户发送消息
           </div>
           <FormItem v-if="blackWhiteForm.isBlockListEnabledt" name="groupBlockList" label="">
@@ -172,11 +150,11 @@
           <Switch v-model:checked="blackWhiteForm.isGroupBlockListEnabled" />
           <div
             v-if="blackWhiteForm.isGroupBlockListEnabled"
-            style="foon-size: 12px; margin-top: 10px; color: #9a9a9a"
+            style="margin-top: 10px; color: #9a9a9a; font-size: 12px;"
           >
             黑名单优先级高于白名单
           </div>
-          <div v-else style="foon-size: 12px; margin-top: 10px; color: #9a9a9a">
+          <div v-else style="margin-top: 10px; color: #9a9a9a; font-size: 12px;">
             关闭黑名单表示允许向所有客群发送消息
           </div>
           <FormItem v-if="blackWhiteForm.isGroupBlockListEnabled" name="groupBlockList" label="">
@@ -217,10 +195,11 @@
         :scroll="{ y: '50vh' }"
       ></Table>
     </Modal>
+    <SelectAIAgentModal @register="registerAIAgentModal" @ok="handleUpdateAgent" />
   </div>
 </template>
 <script lang="ts" setup>
-  import { createVNode, defineComponent, ref, onMounted, reactive, computed } from 'vue';
+  import { createVNode, ref, onMounted, reactive } from 'vue';
   import {
     Modal,
     message,
@@ -228,20 +207,17 @@
     FormItem,
     Select,
     Switch,
-    SwitchItem,
     RadioGroup,
     RadioButton,
     Table
   } 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 { BasicModal, useModal } from '/@/components/Modal';
   import { refreshLoginQRApi } from '@/api/wechat/wxhook';
   import { getPermCode } from '@/api/sys/user';
   import { useDrawer } from '@/components/Drawer';
   import WxDrawer from './WxDrawer.vue';
-  import { getAgentList } from '@/api/wechat/agent';
   import { getServerList, RefreshWorkPhone } from '@/api/wechat/server';
   import { getContactList } from '@/api/wechat/contact';
   import { useI18n } from 'vue-i18n';
@@ -250,7 +226,6 @@
   import {
     getWxList,
     deleteWx,
-    createWx,
     updateWx,
     checkWx,
     getBlackWhiteList,
@@ -260,14 +235,14 @@
   import { getUsageDetailList } from '@/api/wechat/usageDetail'
   import type { TabsProps } from 'ant-design-vue';
   import {formatToDateTime} from "@/utils/dateUtil";
+  import SelectAIAgentModal from '@/views/components/ SelectAIAgentModal.vue';
+
   const blockType = ref<TabsProps['all']>('part');
   const blockGroupType = ref<TabsProps['all']>('part');
   const searchFormSchema = ref<FormSchema[]>([]);
   const { t } = useI18n();
   const selectedIds = ref<number[] | string[]>();
   const showDeleteButton = ref<boolean>(false);
-  let modeList = ref([]);
-  const modalVisible = ref(false);
   const blackWhiteModalVisible = ref(false);
   const tokenVisible = ref(false);
   const loading = ref(false); // 添加 loading 状态
@@ -316,7 +291,6 @@
   });
 
   let permCode = ref('');
-  const tableData = ref([]);
   let accountId = ref(undefined);
   let recordList = reactive({
     serverId: undefined,
@@ -324,7 +298,8 @@
     callback: undefined,
   });
   const [registerDrawer, { openDrawer }] = useDrawer();
-  const [registerModal, { openModal, setModalProps, closeModal }] = useModal();
+  const [registerModal, { openModal, closeModal }] = useModal();
+  const [registerAIAgentModal, { openModal: openAIAgentModal, closeModal: closeAIAgentModal }] = useModal();
   const isUpdate = ref(true);
   let modalContent = ref('');
   const [registerTable, { reload }] = useTable({
@@ -402,18 +377,6 @@
   onMounted(async () => {
     let res = await getPermCode();
     permCode.value = res.data[0];
-    let data = await getAgentList({ page: 1, pageSize: 1000 });
-    const dataArray = Array.isArray(data?.data?.data)
-      ? data.data.data
-      : data?.data?.data
-      ? Array.from(data.data.data)
-      : [];
-
-    modeList.value = dataArray.map((item: any) => ({
-      label: item.name, // 确保使用 label 和 value
-      value: item.id,
-    }));
-    modeList.value.unshift({ label: '定制 AI 角色', value: 0 });
     searchFormSchema.value = [
       {
         field: 'serverId',
@@ -674,20 +637,12 @@
     accountId.value = record.id;
     const name = record.agentInfo?.name == null ? '定制 AI 角色' : record.agentInfo?.name;
     const id = record.agentInfo?.id == null ? 0 : record.agentInfo?.id;
-    Object.assign(form, {
-      name: name,
-      id: id,
-    });
-    modalVisible.value = true;
-  }
-  async function handleOk() {
-    let res = await updateWx({ agentId: form.id, id: accountId.value });
-    message.success('success');
-    modalVisible.value = false;
-    await reload();
-  }
-  async function handleCancel() {
-    Object.assign(form, initialForm);
+    openAIAgentModal(true, {
+      accountId: record.id,
+      name,
+      id,
+      organizationId: record.organizationId
+    })
   }
   //登陆
   function handleLogin(record: Recordable) {
@@ -766,8 +721,9 @@
       },
     });
   }
-
-  async function handleSuccess() {
-    await reload();
+  async function handleUpdateAgent(params) {
+    await updateWx(params);
+    closeAIAgentModal();
+    reload()
   }
 </script>