From 730a3152d7a11eae2f1cea82a88182dbf97705b6 Mon Sep 17 00:00:00 2001 From: ldq <1582649509@qq.com> Date: Mon, 26 Aug 2024 08:44:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=90=9C=E7=B4=A2=E6=9C=BA=E5=99=A8?= =?UTF-8?q?=E4=BA=BA=E5=AE=A2=E6=88=B7=20=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin-bind-bot-relation/package.json | 4 +- .../src/client/client.d.ts | 24 +++---- .../src/client/component/BotDetails.tsx | 71 ++++++++++--------- .../src/client/initializer/index.tsx | 25 ++++++- .../src/client/schema/index.ts | 5 +- .../src/client/settings/index.ts | 3 +- .../src/client/settings/items/botField.ts | 9 ++- .../src/locale/en-US.json | 2 + .../src/locale/zh-CN.json | 2 + 9 files changed, 91 insertions(+), 54 deletions(-) diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/package.json b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/package.json index 38d319dd1f..51d0cd9c3b 100644 --- a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/package.json +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/package.json @@ -1,11 +1,11 @@ { "name": "@nocobase-sample/plugin-bind-bot-relation", - "version": "1.3.1-alpha", + "version": "1.3.4-alpha", "main": "dist/server/index.js", "displayName": "Bind the robot crowd/friend relationship", "displayName.zh-CN": "绑定机器人群/好友关系", "description": "Call the enterprise brain to search the robot crowd/friend relationship data, select and bind customers.", - "description.zh-CN": "调用企业大脑搜索机器人群/好友关系数据,选择并绑定客户。124", + "description.zh-CN": "调用企业大脑搜索机器人群/好友关系数据,选择并绑定客户。", "dependencies": {}, "peerDependencies": { "@nocobase/client": "1.x", diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/client.d.ts b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/client.d.ts index 4e96f83fa1..52638aa656 100644 --- a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/client.d.ts +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/client.d.ts @@ -44,14 +44,14 @@ declare module '*.module.sss' { } // CSS -declare module '*.css' { } -declare module '*.scss' { } -declare module '*.sass' { } -declare module '*.less' { } -declare module '*.styl' { } -declare module '*.stylus' { } -declare module '*.pcss' { } -declare module '*.sss' { } +declare module '*.css' {} +declare module '*.scss' {} +declare module '*.sass' {} +declare module '*.less' {} +declare module '*.styl' {} +declare module '*.stylus' {} +declare module '*.pcss' {} +declare module '*.sss' {} // Built-in asset types // see `src/node/constants.ts` @@ -197,14 +197,14 @@ declare module '*.wasm?init' { // web worker declare module '*?worker' { const workerConstructor: { - new(options?: { name?: string }): Worker; + new (options?: { name?: string }): Worker; }; export default workerConstructor; } declare module '*?worker&inline' { const workerConstructor: { - new(options?: { name?: string }): Worker; + new (options?: { name?: string }): Worker; }; export default workerConstructor; } @@ -216,14 +216,14 @@ declare module '*?worker&url' { declare module '*?sharedworker' { const sharedWorkerConstructor: { - new(options?: { name?: string }): SharedWorker; + new (options?: { name?: string }): SharedWorker; }; export default sharedWorkerConstructor; } declare module '*?sharedworker&inline' { const sharedWorkerConstructor: { - new(options?: { name?: string }): SharedWorker; + new (options?: { name?: string }): SharedWorker; }; export default sharedWorkerConstructor; } diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/component/BotDetails.tsx b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/component/BotDetails.tsx index 4d4294739f..d8de032b30 100644 --- a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/component/BotDetails.tsx +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/component/BotDetails.tsx @@ -17,33 +17,44 @@ import { TableView } from './TableView'; import axios from 'axios'; export interface BotDetailsProps { - BotField?: string; + BotField: string; + SearchScope: number; } +// 查个人信息 获取所属协会信息 +const useSearchAssicontionInfo = (associationUrl: string) => { + let associationId = null; + const { data } = useRequest<{ data: any }>({ url: '/auth:check' }); + associationId = data?.data.f_business_association_id || data?.data.f_belong_association_id; + // 查商会表 获取该协会信息 + const { data: associationData } = useRequest<{ data: any }>( + { url: associationUrl + associationId }, + { + ready: !!associationId, // 只有在 associationId 有值时才触发请求 + }, + ); + const apiKey = associationData?.data['api-key'] || associationData?.data['api_key']; + return { apiKey }; +}; + export const BotDetails: FC = observer( - ({ BotField }) => { + ({ BotField, SearchScope }) => { const form = useForm(); const value = BotField ? form.values[BotField] : undefined; if (!BotField) return
请选择绑定字段
; let xAppApiKey = null; - let associationId = null; - const baseUrl = 'http://192.168.11.124:4000/api/'; - const associationUrl = '/association:get/'; - // const baseUrl = 'https://api.gemelai.com/api/'; - // const associationUrl = '/business_association:get/'; + const searchGroup = [1, 3].includes(SearchScope); + const searchFriend = [2, 3].includes(SearchScope); - // 查个人信息 获取所属协会id - const { data } = useRequest<{ data: any }>({ url: '/auth:check' }); - associationId = data?.data.f_business_association_id || data?.data.f_belong_association_id; - // 查商会表 获取该协会信息 - const { data: associationData } = useRequest<{ data: any }>( - { url: associationUrl + associationId }, - { - ready: !!associationId, // 只有在 associationId 有值时才触发请求 - }, - ); - xAppApiKey = associationData?.data['api-key'] || associationData?.data['api_key']; + // const baseUrl = 'http://192.168.11.124:4000/api/'; + // const baseUrl = 'https://brain-api.we17.fun/api/'; + // const associationUrl = '/association:get/'; + const baseUrl = 'https://api.gemelai.com/api/'; + const associationUrl = '/business_association:get/'; + + const { apiKey } = useSearchAssicontionInfo(associationUrl); // 获取apiKey + xAppApiKey = apiKey; localStorage.setItem( 'PLUGIN-BIND-BOT-RELATION', @@ -65,7 +76,7 @@ export const BotDetails: FC = observer( `${baseUrl}open/bot/bind-groups`, { keyword: value, - limit: 2, + limit: 3, }, { headers: { @@ -75,7 +86,7 @@ export const BotDetails: FC = observer( }, ), { - ready: !!value && !!xAppApiKey, + ready: !!value && !!xAppApiKey && searchGroup, refreshDeps: [BotField, value], debounceWait: 300, }, @@ -86,7 +97,7 @@ export const BotDetails: FC = observer( `${baseUrl}open/bot/bind-friends`, { keyword: value, - limit: 2, + limit: 3, }, { headers: { @@ -96,22 +107,16 @@ export const BotDetails: FC = observer( }, ), { - ready: !!value && !!xAppApiKey, + ready: !!value && !!xAppApiKey && searchFriend, refreshDeps: [BotField, value], debounceWait: 300, }, ); const Error: any = error; - if (Error || !xAppApiKey) { - return !value ? ( - - ) : !xAppApiKey ? ( - - ) : ( - {Error?.response?.data?.message}} /> - ); - } + if (!value) return ; + if (!xAppApiKey) return ; + if (Error) return {Error?.response?.data?.message}} />; if (groupLoading || friendLoading) { return ( @@ -121,8 +126,8 @@ export const BotDetails: FC = observer( ); } - const groupDataResult = groupData ? groupData.data?.result : []; - const friendDataResult = friendData ? friendData.data?.result : []; + const groupDataResult = groupData && searchGroup ? groupData.data?.result : []; + const friendDataResult = friendData && searchFriend ? friendData.data?.result : []; if (groupDataResult.length === 0 && friendDataResult.length === 0) return ; return ; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/initializer/index.tsx b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/initializer/index.tsx index 1790fb4194..11bf964ced 100644 --- a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/initializer/index.tsx +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/initializer/index.tsx @@ -16,7 +16,6 @@ import { useCollection, useCompile, useSchemaInitializer, - SchemaSettingsDefaultValue, } from '@nocobase/client'; import { SearchOutlined } from '@ant-design/icons'; import { FieldNameLowercase } from '../constants'; @@ -32,6 +31,15 @@ export function useFieldOptions(): SelectProps['options'] { .map((field) => ({ label: field.uiSchema?.title ? compile(field.uiSchema.title) : field.name, value: field.name })); } +export function useSearchScopeOptions(): SelectProps['options'] { + const searchScopeOptions: any = [ + { label: '群', value: 1 }, + { label: '好友', value: 2 }, + { label: '群 + 好友', value: 3 }, + ]; + return searchScopeOptions.map((field: any) => ({ label: field.label, value: field.value })); +} + const BotDetailsSchemaInitializer = () => { const t = useT(); const { insert } = useSchemaInitializer(); @@ -48,8 +56,8 @@ const BotDetailsSchemaInitializer = () => { title={t('Select bind Field')} icon={} isItem - onSubmit={({ BotField }) => { - insert(getBotDetailsSchema(BotField)); + onSubmit={({ BotField, SearchScope }) => { + insert(getBotDetailsSchema(BotField, SearchScope)); }} schema={{ BotField: { @@ -63,6 +71,17 @@ const BotDetailsSchemaInitializer = () => { 'x-decorator': 'FormItem', enum: options, }, + SearchScope: { + type: 'number', + title: t('Search scope'), + required: true, + 'x-component': 'Select', + 'x-component-props': { + placeholder: t('Please select search scope'), + }, + 'x-decorator': 'FormItem', + enum: useSearchScopeOptions(), + }, // ApiKey: { // type: 'string', // title: 'API Key', diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/schema/index.ts b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/schema/index.ts index a89f921039..81ad8d4f8d 100644 --- a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/schema/index.ts +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/schema/index.ts @@ -11,13 +11,14 @@ import { ISchema } from '@nocobase/client'; import { FieldComponentName } from '../constants'; import { botDetailsSettings } from '../settings'; -export const getBotDetailsSchema = (BotField: string): ISchema => ({ +export const getBotDetailsSchema = (BotField: string, SearchScope: number): ISchema => ({ type: 'void', 'x-decorator': 'FormItem', 'x-toolbar': 'FormItemSchemaToolbar', 'x-component': FieldComponentName, 'x-component-props': { - BotField: BotField, + BotField, + SearchScope, }, 'x-settings': botDetailsSettings.name, }); diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/settings/index.ts b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/settings/index.ts index 6eec25df75..6ab57c705c 100644 --- a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/settings/index.ts +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/settings/index.ts @@ -9,12 +9,13 @@ import { SchemaSettings } from '@nocobase/client'; import { FieldNameLowercase } from '../constants'; -import { botFieldSchemaSettingsItem } from './items/botField'; +import { botFieldSchemaSettingsItem, changeSearchFieldSchemaSettingsItem } from './items/botField'; export const botDetailsSettings = new SchemaSettings({ name: `blockSettings:${FieldNameLowercase}`, items: [ botFieldSchemaSettingsItem, + changeSearchFieldSchemaSettingsItem, { name: 'remove', type: 'remove', diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/settings/items/botField.ts b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/settings/items/botField.ts index 0a69f714cb..f0dad95c57 100644 --- a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/settings/items/botField.ts +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/settings/items/botField.ts @@ -9,7 +9,7 @@ import { createSelectSchemaSettingsItem } from '@nocobase/client'; import { tStr } from '../../locale'; -import { useFieldOptions } from '../../initializer'; +import { useFieldOptions, useSearchScopeOptions } from '../../initializer'; export const botFieldSchemaSettingsItem = createSelectSchemaSettingsItem({ name: 'BotField', @@ -17,3 +17,10 @@ export const botFieldSchemaSettingsItem = createSelectSchemaSettingsItem({ useOptions: useFieldOptions, schemaKey: `x-component-props.BotField`, }); + +export const changeSearchFieldSchemaSettingsItem = createSelectSchemaSettingsItem({ + name: 'ChangeSearchField', + title: tStr('Search scope'), + useOptions: useSearchScopeOptions, + schemaKey: `x-component-props.SearchScope`, +}); diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/locale/en-US.json b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/locale/en-US.json index 7ed3529a30..ee2367af7a 100644 --- a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/locale/en-US.json +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/locale/en-US.json @@ -2,5 +2,7 @@ "Bot Details": "Bot Details", "Select bind Field": "Select bind Field", "Please select a field": "Please select a field", + "Search scope": "Search scope", + "Please select search scope": "Please select search scope", "Bind field": "Bind field" } \ No newline at end of file diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/locale/zh-CN.json b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/locale/zh-CN.json index 9c8931f98d..042734b2ab 100644 --- a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/locale/zh-CN.json +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/locale/zh-CN.json @@ -2,5 +2,7 @@ "Bot Details": "搜索机器人客户", "Select bind Field": "选择绑定字段", "Please select a field": "请选择绑定字段", + "Search scope": "搜索范围", + "Please select search scope": "请选择搜索范围", "Bind field": "绑定字段" } \ No newline at end of file