diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/.npmignore b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/.npmignore new file mode 100644 index 0000000000..65f5e8779f --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/.npmignore @@ -0,0 +1,2 @@ +/node_modules +/src diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/README.md b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/README.md new file mode 100644 index 0000000000..42cf85209e --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/README.md @@ -0,0 +1 @@ +# @nocobase-sample/plugin-bind-bot-relation diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/client.d.ts b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/client.d.ts new file mode 100644 index 0000000000..6c459cbac4 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/client.d.ts @@ -0,0 +1,2 @@ +export * from './dist/client'; +export { default } from './dist/client'; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/client.js b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/client.js new file mode 100644 index 0000000000..b6e3be70e6 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/client.js @@ -0,0 +1 @@ +module.exports = require('./dist/client/index.js'); diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/package.json b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/package.json new file mode 100644 index 0000000000..38d319dd1f --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/package.json @@ -0,0 +1,15 @@ +{ + "name": "@nocobase-sample/plugin-bind-bot-relation", + "version": "1.3.1-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", + "dependencies": {}, + "peerDependencies": { + "@nocobase/client": "1.x", + "@nocobase/server": "1.x", + "@nocobase/test": "1.x" + } +} \ No newline at end of file diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/server.d.ts b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/server.d.ts new file mode 100644 index 0000000000..c41081ddc6 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/server.d.ts @@ -0,0 +1,2 @@ +export * from './dist/server'; +export { default } from './dist/server'; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/server.js b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/server.js new file mode 100644 index 0000000000..972842039a --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/server.js @@ -0,0 +1 @@ +module.exports = require('./dist/server/index.js'); 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 new file mode 100644 index 0000000000..4e96f83fa1 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/client.d.ts @@ -0,0 +1,249 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +// CSS modules +type CSSModuleClasses = { readonly [key: string]: string }; + +declare module '*.module.css' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.scss' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.sass' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.less' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.styl' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.stylus' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.pcss' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.sss' { + const classes: CSSModuleClasses; + export default classes; +} + +// 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' { } + +// Built-in asset types +// see `src/node/constants.ts` + +// images +declare module '*.apng' { + const src: string; + export default src; +} +declare module '*.png' { + const src: string; + export default src; +} +declare module '*.jpg' { + const src: string; + export default src; +} +declare module '*.jpeg' { + const src: string; + export default src; +} +declare module '*.jfif' { + const src: string; + export default src; +} +declare module '*.pjpeg' { + const src: string; + export default src; +} +declare module '*.pjp' { + const src: string; + export default src; +} +declare module '*.gif' { + const src: string; + export default src; +} +declare module '*.svg' { + const src: string; + export default src; +} +declare module '*.ico' { + const src: string; + export default src; +} +declare module '*.webp' { + const src: string; + export default src; +} +declare module '*.avif' { + const src: string; + export default src; +} + +// media +declare module '*.mp4' { + const src: string; + export default src; +} +declare module '*.webm' { + const src: string; + export default src; +} +declare module '*.ogg' { + const src: string; + export default src; +} +declare module '*.mp3' { + const src: string; + export default src; +} +declare module '*.wav' { + const src: string; + export default src; +} +declare module '*.flac' { + const src: string; + export default src; +} +declare module '*.aac' { + const src: string; + export default src; +} +declare module '*.opus' { + const src: string; + export default src; +} +declare module '*.mov' { + const src: string; + export default src; +} +declare module '*.m4a' { + const src: string; + export default src; +} +declare module '*.vtt' { + const src: string; + export default src; +} + +// fonts +declare module '*.woff' { + const src: string; + export default src; +} +declare module '*.woff2' { + const src: string; + export default src; +} +declare module '*.eot' { + const src: string; + export default src; +} +declare module '*.ttf' { + const src: string; + export default src; +} +declare module '*.otf' { + const src: string; + export default src; +} + +// other +declare module '*.webmanifest' { + const src: string; + export default src; +} +declare module '*.pdf' { + const src: string; + export default src; +} +declare module '*.txt' { + const src: string; + export default src; +} + +// wasm?init +declare module '*.wasm?init' { + const initWasm: (options?: WebAssembly.Imports) => Promise; + export default initWasm; +} + +// web worker +declare module '*?worker' { + const workerConstructor: { + new(options?: { name?: string }): Worker; + }; + export default workerConstructor; +} + +declare module '*?worker&inline' { + const workerConstructor: { + new(options?: { name?: string }): Worker; + }; + export default workerConstructor; +} + +declare module '*?worker&url' { + const src: string; + export default src; +} + +declare module '*?sharedworker' { + const sharedWorkerConstructor: { + new(options?: { name?: string }): SharedWorker; + }; + export default sharedWorkerConstructor; +} + +declare module '*?sharedworker&inline' { + const sharedWorkerConstructor: { + new(options?: { name?: string }): SharedWorker; + }; + export default sharedWorkerConstructor; +} + +declare module '*?sharedworker&url' { + const src: string; + export default src; +} + +declare module '*?raw' { + const src: string; + export default src; +} + +declare module '*?url' { + const src: string; + export default src; +} + +declare module '*?inline' { + const src: string; + export default src; +} 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 new file mode 100644 index 0000000000..4d4294739f --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/component/BotDetails.tsx @@ -0,0 +1,131 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { observer } from '@formily/react'; +import { Spin, Empty, Typography } from 'antd'; +import React, { FC } from 'react'; +import { useForm } from '@formily/react'; +import { FieldComponentName } from '../constants'; +import { useRequest } from '@nocobase/client'; +import { TableView } from './TableView'; +import axios from 'axios'; + +export interface BotDetailsProps { + BotField?: string; +} + +export const BotDetails: FC = observer( + ({ BotField }) => { + 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/'; + + // 查个人信息 获取所属协会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']; + + localStorage.setItem( + 'PLUGIN-BIND-BOT-RELATION', + JSON.stringify({ + baseUrl, + associationUrl, + xAppApiKey, + }), + ); + + // 根据apikey 查企业大脑对应的绑定关系 + const { + data: groupData, + loading: groupLoading, + error, + } = useRequest<{ data: any; error: any }>( + () => + axios.post( + `${baseUrl}open/bot/bind-groups`, + { + keyword: value, + limit: 2, + }, + { + headers: { + 'Content-Type': 'application/json', + 'x-app-api-key': xAppApiKey, + }, + }, + ), + { + ready: !!value && !!xAppApiKey, + refreshDeps: [BotField, value], + debounceWait: 300, + }, + ); + const { data: friendData, loading: friendLoading } = useRequest<{ data: any }>( + () => + axios.post( + `${baseUrl}open/bot/bind-friends`, + { + keyword: value, + limit: 2, + }, + { + headers: { + 'Content-Type': 'application/json', + 'x-app-api-key': xAppApiKey, + }, + }, + ), + { + ready: !!value && !!xAppApiKey, + refreshDeps: [BotField, value], + debounceWait: 300, + }, + ); + const Error: any = error; + + if (Error || !xAppApiKey) { + return !value ? ( + + ) : !xAppApiKey ? ( + + ) : ( + {Error?.response?.data?.message}} /> + ); + } + + if (groupLoading || friendLoading) { + return ( +
+ +
+ ); + } + + const groupDataResult = groupData ? groupData.data?.result : []; + const friendDataResult = friendData ? friendData.data?.result : []; + if (groupDataResult.length === 0 && friendDataResult.length === 0) return ; + + return ; + }, + { displayName: FieldComponentName }, +); diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/component/ImIcon.tsx b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/component/ImIcon.tsx new file mode 100644 index 0000000000..38748e1172 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/component/ImIcon.tsx @@ -0,0 +1,50 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import React from 'react'; +import { + AiWebsiteIcon, + AlibabaTmIcon, + LiveCustomerIcon, + QqIcon, + TiktokIcon, + WechatIcon, + WecomIcon, + WhatsappBotIcon, + XhsIcon, +} from '../svg'; + +interface ImIconProps { + im: string; +} + +export const ImIcon = ({ im }: ImIconProps) => { + switch (im) { + case 'alibaba-tm': + return ; + case 'wecom': + return ; + case 'wechat': + return ; + case 'whatsapp-bot': + return ; + case 'qq': + return ; + case 'tiktok': + return ; + case 'xhs': + return ; + case 'live-customer': + return ; + case 'ai-website': + return ; + default: + return null; + } +}; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/component/TableView.tsx b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/component/TableView.tsx new file mode 100644 index 0000000000..0e321f95a2 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/component/TableView.tsx @@ -0,0 +1,159 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import React from 'react'; +import { Table, Avatar, Flex, Space, Button, message, Empty } from 'antd'; +import type { TableColumnsType } from 'antd'; +import { filterCustomerSource } from '../utils'; +import { ImIcon } from './ImIcon'; +import { useForm } from '@formily/react'; +import { FriendIcon, GroupIcon } from '../svg'; + +interface DataItem { + key: React.Key; + id: number; + platform: string; + bindId: string; + botUserId: string; + groupName?: string; + avatarUrl?: string; + nickName?: string; + userId?: string; + groupId?: string; + remark: string; +} + +export const TableView = ({ data }) => { + const form = useForm(); + const [messageApi, contextHolder] = message.useMessage(); + + const columns: TableColumnsType = [ + { + title: 'IM平台', + dataIndex: 'platform', + render: (_, record) => { + return ( + + + {filterCustomerSource(record.platform)} + + ); + }, + align: 'center', + }, + { + title: '群/好友名称', + dataIndex: 'groupName', + render: (_, record) => { + if (record.groupName) { + return ( + + + {record.groupName} + + ); + } + if (record.nickName) { + return ( + + + {record.avatarUrl ? : <>} + {record.nickName} + + ); + } + }, + align: 'center', + }, + { + title: '群/好友id', + dataIndex: 'userId', + render: (_, record) => { + if (record.groupId) { + return {record.groupId}; + } + if (record.userId) { + return {record.userId}; + } + }, + align: 'center', + }, + { + title: '备注', + dataIndex: 'remark', + align: 'center', + }, + { + title: '操作', + width: 120, + fixed: 'right', + align: 'center', + render: (_, record) => ( + + + + ), + }, + ]; + + const saveBind = (record: DataItem) => { + const fields: any = form.fields || {}; + const { platform, groupId, userId, avatarUrl, groupName, nickName, remark, botUserId } = record; + + for (const key in fields) { + const name = fields[key].props.name; + if (name) { + switch (name) { + case 'imName': + fields[key].value = groupName || nickName; + break; + case 'imPlatform': + fields[key].value = platform; + break; + case 'imBotUserId': + fields[key].value = botUserId; + break; + case 'imIsGroup': + fields[key].value = groupName ? '群' : '好友'; + break; + case 'imUserId': + fields[key].value = groupId || userId; + break; + case 'imAvatarUrl': + fields[key].value = avatarUrl; + break; + case 'imRemark': + fields[key].value = remark; + break; + } + } + } + + messageApi.success(`绑定成功,请检查对应信息。`); + }; + + return ( + <> + {contextHolder} + ({ + ...item, + key: item.id, + }))} + columns={columns} + bordered + scroll={{ y: '260px' }} + pagination={false} + style={{ padding: '0 20px' }} + /> + + ); +}; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/component/index.ts b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/component/index.ts new file mode 100644 index 0000000000..7fe0fd22e4 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/component/index.ts @@ -0,0 +1,10 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +export * from './BotDetails'; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/constants.ts b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/constants.ts new file mode 100644 index 0000000000..7bd478ddb1 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/constants.ts @@ -0,0 +1,12 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +export const FieldComponentName = 'BotDetails'; +export const FieldTitle = 'Bot Details'; +export const FieldNameLowercase = 'brderDetails'; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/index.tsx b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/index.tsx new file mode 100644 index 0000000000..73f2bdf6a0 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/index.tsx @@ -0,0 +1,68 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import React from 'react'; +import { Plugin, SchemaComponent } from '@nocobase/client'; +import { BotDetails } from './component'; +import { FieldComponentName } from './constants'; +import { botDetailsInitializerItem } from './initializer'; +import { botDetailsSettings } from './settings'; + +export class PluginFieldComponentWithoutValueClient extends Plugin { + async load() { + this.app.addComponents({ [FieldComponentName]: BotDetails }); + + // function Demo() { + // const schema = { + // type: 'void', + // name: 'root', + // properties: { + // test: { + // type: 'void', + // 'x-component': 'FormV2', + // properties: { + // username: { + // type: 'string', + // 'x-decorator': 'FormItem', + // 'x-component': 'Input', + // title: 'Username', + // required: true, + // }, + // orderDetails: { + // type: 'string', + // 'x-decorator': 'FormItem', + // 'x-component': BotDetails, + // title: '机器人', + // 'x-component-props': { + // orderField: 'username', + // }, + // }, + // }, + // }, + // }, + // }; + + // return ; + // } + + // this.app.router.add('admin.order-details-component', { + // path: '/admin/order-details-component', + // Component: Demo, + // }); + + this.app.schemaInitializerManager.addItem( + 'form:configureFields', + botDetailsInitializerItem.name, + botDetailsInitializerItem, + ); + this.app.schemaSettingsManager.add(botDetailsSettings); + } +} + +export default PluginFieldComponentWithoutValueClient; 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 new file mode 100644 index 0000000000..1790fb4194 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/initializer/index.tsx @@ -0,0 +1,84 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import React, { useCallback } from 'react'; +import _ from 'lodash'; +import { + SchemaInitializerActionModal, + SchemaInitializerItemType, + SelectProps, + useCollection, + useCompile, + useSchemaInitializer, + SchemaSettingsDefaultValue, +} from '@nocobase/client'; +import { SearchOutlined } from '@ant-design/icons'; +import { FieldNameLowercase } from '../constants'; +import { useT } from '../locale'; +import { getBotDetailsSchema } from '../schema'; + +export function useFieldOptions(): SelectProps['options'] { + const collection = useCollection(); + + const compile = useCompile(); + return collection + .getFields() + .map((field) => ({ label: field.uiSchema?.title ? compile(field.uiSchema.title) : field.name, value: field.name })); +} + +const BotDetailsSchemaInitializer = () => { + const t = useT(); + const { insert } = useSchemaInitializer(); + const options = useFieldOptions(); + + const scope = [ + { label: 'v1', value: 'v1' }, + { label: 'nested', value: 'nested', children: [{ label: 'v2', value: 'v2' }] }, + ]; + + return ( + } + isItem + onSubmit={({ BotField }) => { + insert(getBotDetailsSchema(BotField)); + }} + schema={{ + BotField: { + type: 'string', + title: t('Bind field'), + required: true, + 'x-component': 'Select', + 'x-component-props': { + placeholder: t('Please select a field'), + }, + 'x-decorator': 'FormItem', + enum: options, + }, + // ApiKey: { + // type: 'string', + // title: 'API Key', + // required: true, + // 'x-component': 'Variable.Input', + // 'x-component-props': { + // scope, + // }, + // 'x-decorator': 'FormItem', + // }, + }} + > + ); +}; + +export const botDetailsInitializerItem: SchemaInitializerItemType = { + name: FieldNameLowercase, + Component: BotDetailsSchemaInitializer, +}; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/locale.ts b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/locale.ts new file mode 100644 index 0000000000..84797b7d1b --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/locale.ts @@ -0,0 +1,21 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +// @ts-ignore +import pkg from './../../package.json'; +import { useApp } from '@nocobase/client'; + +export function useT() { + const app = useApp(); + return (str: string) => app.i18n.t(str, { ns: [pkg.name, 'client'] }); +} + +export function tStr(key: string) { + return `{{t(${JSON.stringify(key)}, { ns: ['${pkg.name}', 'client'], nsMode: 'fallback' })}}`; +} 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 new file mode 100644 index 0000000000..a89f921039 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/schema/index.ts @@ -0,0 +1,23 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { ISchema } from '@nocobase/client'; +import { FieldComponentName } from '../constants'; +import { botDetailsSettings } from '../settings'; + +export const getBotDetailsSchema = (BotField: string): ISchema => ({ + type: 'void', + 'x-decorator': 'FormItem', + 'x-toolbar': 'FormItemSchemaToolbar', + 'x-component': FieldComponentName, + 'x-component-props': { + BotField: BotField, + }, + '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 new file mode 100644 index 0000000000..6eec25df75 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/settings/index.ts @@ -0,0 +1,29 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { SchemaSettings } from '@nocobase/client'; +import { FieldNameLowercase } from '../constants'; +import { botFieldSchemaSettingsItem } from './items/botField'; + +export const botDetailsSettings = new SchemaSettings({ + name: `blockSettings:${FieldNameLowercase}`, + items: [ + botFieldSchemaSettingsItem, + { + name: 'remove', + type: 'remove', + componentProps: { + removeParentsIfNoChildren: true, + breakRemoveOn: { + 'x-component': 'Grid', + }, + }, + }, + ], +}); 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 new file mode 100644 index 0000000000..0a69f714cb --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/settings/items/botField.ts @@ -0,0 +1,19 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { createSelectSchemaSettingsItem } from '@nocobase/client'; +import { tStr } from '../../locale'; +import { useFieldOptions } from '../../initializer'; + +export const botFieldSchemaSettingsItem = createSelectSchemaSettingsItem({ + name: 'BotField', + title: tStr('Bind field'), + useOptions: useFieldOptions, + schemaKey: `x-component-props.BotField`, +}); diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/aiWebsiteIcon.tsx b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/aiWebsiteIcon.tsx new file mode 100644 index 0000000000..ae4e9bf99e --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/aiWebsiteIcon.tsx @@ -0,0 +1,28 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import React from 'react'; + +export const AiWebsiteIcon = () => { + return ( + + + + ); +}; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/alibabaTmIcon.tsx b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/alibabaTmIcon.tsx new file mode 100644 index 0000000000..71717bda55 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/alibabaTmIcon.tsx @@ -0,0 +1,28 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import React from 'react'; + +export const AlibabaTmIcon = () => { + return ( + + + + ); +}; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/friendIcon.tsx b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/friendIcon.tsx new file mode 100644 index 0000000000..f4aba35ec2 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/friendIcon.tsx @@ -0,0 +1,28 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import React from 'react'; + +export const FriendIcon = () => { + return ( + + + + ); +}; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/groupIcon.tsx b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/groupIcon.tsx new file mode 100644 index 0000000000..c7847053c8 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/groupIcon.tsx @@ -0,0 +1,28 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import React from 'react'; + +export const GroupIcon = () => { + return ( + + + + ); +}; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/index.ts b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/index.ts new file mode 100644 index 0000000000..4182ffe40d --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/index.ts @@ -0,0 +1,20 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +export * from './wechatIcon'; +export * from './qqIcon'; +export * from './alibabaTmIcon'; +export * from './wecomIcon'; +export * from './whatsappBotIcon'; +export * from './tiktokIcon'; +export * from './xhsIcon'; +export * from './liveCustomerIcon'; +export * from './aiWebsiteIcon'; +export * from './groupIcon'; +export * from './friendIcon'; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/liveCustomerIcon.tsx b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/liveCustomerIcon.tsx new file mode 100644 index 0000000000..c745f59d82 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/liveCustomerIcon.tsx @@ -0,0 +1,33 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import React from 'react'; + +export const LiveCustomerIcon = () => { + return ( + + + + + + ); +}; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/qqIcon.tsx b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/qqIcon.tsx new file mode 100644 index 0000000000..88b706d685 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/qqIcon.tsx @@ -0,0 +1,33 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import React from 'react'; + +export const QqIcon = () => { + return ( + + + + + + ); +}; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/tiktokIcon.tsx b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/tiktokIcon.tsx new file mode 100644 index 0000000000..8727861ae1 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/tiktokIcon.tsx @@ -0,0 +1,36 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import React from 'react'; + +export const TiktokIcon = () => { + return ( + + + + + + ); +}; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/wechatIcon.tsx b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/wechatIcon.tsx new file mode 100644 index 0000000000..43019170d5 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/wechatIcon.tsx @@ -0,0 +1,32 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import React from 'react'; + +export const WechatIcon = () => { + return ( + + + + + ); +}; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/wecomIcon.tsx b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/wecomIcon.tsx new file mode 100644 index 0000000000..7ffbfc2a50 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/wecomIcon.tsx @@ -0,0 +1,44 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import React from 'react'; + +export const WecomIcon = () => { + return ( + + + + + + + + ); +}; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/whatsappBotIcon.tsx b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/whatsappBotIcon.tsx new file mode 100644 index 0000000000..56c3aa14d9 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/whatsappBotIcon.tsx @@ -0,0 +1,28 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import React from 'react'; + +export const WhatsappBotIcon = () => { + return ( + + + + ); +}; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/xhsIcon.tsx b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/xhsIcon.tsx new file mode 100644 index 0000000000..23249ca6e2 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/svg/xhsIcon.tsx @@ -0,0 +1,32 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import React from 'react'; + +export const XhsIcon = () => { + return ( + + + + + ); +}; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/utils/index.ts b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/utils/index.ts new file mode 100644 index 0000000000..e5780198d5 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/client/utils/index.ts @@ -0,0 +1,26 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +// 过滤 客户来源 +export const filterCustomerSource = (value: string) => { + const sceneChannelsList = [ + { name: '阿里TM', value: 'alibaba-tm' }, + { name: '微信', value: 'wechat' }, + { name: '企业微信', value: 'wecom' }, + { name: '企点QQ', value: 'qq' }, + { name: 'WhatsApp', value: 'whatsapp-bot' }, + { name: 'TikTok', value: 'tiktok' }, + { name: '小红书', value: 'xhs' }, + { name: '智能客服', value: 'live-customer' }, + { name: '智能独立站', value: 'ai-website' }, + ]; + + const sourceName = sceneChannelsList.find((item: { value: string }) => item.value === value)?.name; + return sourceName; +}; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/index.ts b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/index.ts new file mode 100644 index 0000000000..be99a2ff1a --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/index.ts @@ -0,0 +1,11 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +export * from './server'; +export { default } from './server'; 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 new file mode 100644 index 0000000000..7ed3529a30 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/locale/en-US.json @@ -0,0 +1,6 @@ +{ + "Bot Details": "Bot Details", + "Select bind Field": "Select bind Field", + "Please select a field": "Please select a field", + "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 new file mode 100644 index 0000000000..9c8931f98d --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/locale/zh-CN.json @@ -0,0 +1,6 @@ +{ + "Bot Details": "搜索机器人客户", + "Select bind Field": "选择绑定字段", + "Please select a field": "请选择绑定字段", + "Bind field": "绑定字段" +} \ No newline at end of file diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/server/collections/.gitkeep b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/server/collections/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/server/index.ts b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/server/index.ts new file mode 100644 index 0000000000..be989de7c3 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/server/index.ts @@ -0,0 +1,10 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +export { default } from './plugin'; diff --git a/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/server/plugin.ts b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/server/plugin.ts new file mode 100644 index 0000000000..dfc09d4df8 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-bind-bot-relation/src/server/plugin.ts @@ -0,0 +1,28 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { Plugin } from '@nocobase/server'; + +export class PluginBindBotRelationServer extends Plugin { + async afterAdd() {} + + async beforeLoad() {} + + async load() {} + + async install() {} + + async afterEnable() {} + + async afterDisable() {} + + async remove() {} +} + +export default PluginBindBotRelationServer; diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/.npmignore b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/.npmignore new file mode 100644 index 0000000000..65f5e8779f --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/.npmignore @@ -0,0 +1,2 @@ +/node_modules +/src diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/README.md b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/README.md new file mode 100644 index 0000000000..d752d699ed --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/README.md @@ -0,0 +1 @@ +# @nocobase-sample/plugin-field-component-without-value diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/client.d.ts b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/client.d.ts new file mode 100644 index 0000000000..6c459cbac4 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/client.d.ts @@ -0,0 +1,2 @@ +export * from './dist/client'; +export { default } from './dist/client'; diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/client.js b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/client.js new file mode 100644 index 0000000000..b6e3be70e6 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/client.js @@ -0,0 +1 @@ +module.exports = require('./dist/client/index.js'); diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/package.json b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/package.json new file mode 100644 index 0000000000..131a7c1ca1 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/package.json @@ -0,0 +1,15 @@ +{ + "name": "@nocobase-sample/plugin-field-component-without-value", + "version": "1.2.35-alpha", + "main": "dist/server/index.js", + "displayName": "Action: Bind group/friend relationship", + "displayName.zh-CN": "绑定群/好友关系Demo", + "description": "", + "description.zh-CN": "", + "dependencies": {}, + "peerDependencies": { + "@nocobase/client": "1.x", + "@nocobase/server": "1.x", + "@nocobase/test": "1.x" + } +} \ No newline at end of file diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/server.d.ts b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/server.d.ts new file mode 100644 index 0000000000..c41081ddc6 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/server.d.ts @@ -0,0 +1,2 @@ +export * from './dist/server'; +export { default } from './dist/server'; diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/server.js b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/server.js new file mode 100644 index 0000000000..972842039a --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/server.js @@ -0,0 +1 @@ +module.exports = require('./dist/server/index.js'); diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/client.d.ts b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/client.d.ts new file mode 100644 index 0000000000..4e96f83fa1 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/client.d.ts @@ -0,0 +1,249 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +// CSS modules +type CSSModuleClasses = { readonly [key: string]: string }; + +declare module '*.module.css' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.scss' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.sass' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.less' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.styl' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.stylus' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.pcss' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.sss' { + const classes: CSSModuleClasses; + export default classes; +} + +// 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' { } + +// Built-in asset types +// see `src/node/constants.ts` + +// images +declare module '*.apng' { + const src: string; + export default src; +} +declare module '*.png' { + const src: string; + export default src; +} +declare module '*.jpg' { + const src: string; + export default src; +} +declare module '*.jpeg' { + const src: string; + export default src; +} +declare module '*.jfif' { + const src: string; + export default src; +} +declare module '*.pjpeg' { + const src: string; + export default src; +} +declare module '*.pjp' { + const src: string; + export default src; +} +declare module '*.gif' { + const src: string; + export default src; +} +declare module '*.svg' { + const src: string; + export default src; +} +declare module '*.ico' { + const src: string; + export default src; +} +declare module '*.webp' { + const src: string; + export default src; +} +declare module '*.avif' { + const src: string; + export default src; +} + +// media +declare module '*.mp4' { + const src: string; + export default src; +} +declare module '*.webm' { + const src: string; + export default src; +} +declare module '*.ogg' { + const src: string; + export default src; +} +declare module '*.mp3' { + const src: string; + export default src; +} +declare module '*.wav' { + const src: string; + export default src; +} +declare module '*.flac' { + const src: string; + export default src; +} +declare module '*.aac' { + const src: string; + export default src; +} +declare module '*.opus' { + const src: string; + export default src; +} +declare module '*.mov' { + const src: string; + export default src; +} +declare module '*.m4a' { + const src: string; + export default src; +} +declare module '*.vtt' { + const src: string; + export default src; +} + +// fonts +declare module '*.woff' { + const src: string; + export default src; +} +declare module '*.woff2' { + const src: string; + export default src; +} +declare module '*.eot' { + const src: string; + export default src; +} +declare module '*.ttf' { + const src: string; + export default src; +} +declare module '*.otf' { + const src: string; + export default src; +} + +// other +declare module '*.webmanifest' { + const src: string; + export default src; +} +declare module '*.pdf' { + const src: string; + export default src; +} +declare module '*.txt' { + const src: string; + export default src; +} + +// wasm?init +declare module '*.wasm?init' { + const initWasm: (options?: WebAssembly.Imports) => Promise; + export default initWasm; +} + +// web worker +declare module '*?worker' { + const workerConstructor: { + new(options?: { name?: string }): Worker; + }; + export default workerConstructor; +} + +declare module '*?worker&inline' { + const workerConstructor: { + new(options?: { name?: string }): Worker; + }; + export default workerConstructor; +} + +declare module '*?worker&url' { + const src: string; + export default src; +} + +declare module '*?sharedworker' { + const sharedWorkerConstructor: { + new(options?: { name?: string }): SharedWorker; + }; + export default sharedWorkerConstructor; +} + +declare module '*?sharedworker&inline' { + const sharedWorkerConstructor: { + new(options?: { name?: string }): SharedWorker; + }; + export default sharedWorkerConstructor; +} + +declare module '*?sharedworker&url' { + const src: string; + export default src; +} + +declare module '*?raw' { + const src: string; + export default src; +} + +declare module '*?url' { + const src: string; + export default src; +} + +declare module '*?inline' { + const src: string; + export default src; +} diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/component/OrderDetails.tsx b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/component/OrderDetails.tsx new file mode 100644 index 0000000000..84359a4148 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/component/OrderDetails.tsx @@ -0,0 +1,49 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { observer } from '@formily/react'; +import { Spin, Empty } from 'antd'; +import React, { FC } from 'react'; +import { useForm } from '@formily/react'; +import { FieldComponentName } from '../constants'; +import { useRequest } from '@nocobase/client'; + +export interface OrderDetailsProps { + orderField?: string; +} + +export const OrderDetails: FC = observer( + ({ orderField }) => { + const form = useForm(); + const value = orderField ? form.values[orderField] : undefined; + + const { data, loading } = useRequest<{ data: any[] }>( + { url: `https://jsonplaceholder.typicode.com/todos/${value}` }, + { + ready: !!value, + refreshDeps: [orderField, value], + }, + ); + + if (!orderField) return
Please select order Field
; + + if (loading) { + return ( +
+ +
+ ); + } + + if (!data) return ; + + return
{JSON.stringify(data, null, 2)}
; + }, + { displayName: FieldComponentName }, +); diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/component/index.ts b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/component/index.ts new file mode 100644 index 0000000000..fcd9e78cf6 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/component/index.ts @@ -0,0 +1,10 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +export * from './OrderDetails'; diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/constants.ts b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/constants.ts new file mode 100644 index 0000000000..2c384f44eb --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/constants.ts @@ -0,0 +1,12 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +export const FieldComponentName = 'OrderDetails'; +export const FieldTitle = 'Order Details'; +export const FieldNameLowercase = 'orderDetails'; diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/index.tsx b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/index.tsx new file mode 100644 index 0000000000..74764d615a --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/index.tsx @@ -0,0 +1,30 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { Plugin, SchemaComponent } from '@nocobase/client'; +import { OrderDetails } from './component'; +import { FieldComponentName } from './constants'; +import { orderDetailsInitializerItem } from './initializer'; +import { orderDetailsSettings } from './settings'; + +export class PluginFieldOrderDetailsClient extends Plugin { + async load() { + this.app.addComponents({ [FieldComponentName]: OrderDetails }); + + this.app.schemaInitializerManager.addItem( + 'form:configureFields', + orderDetailsInitializerItem.name, + orderDetailsInitializerItem, + ); + + this.app.schemaSettingsManager.add(orderDetailsSettings); + } +} + +export default PluginFieldOrderDetailsClient; diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/initializer/index.tsx b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/initializer/index.tsx new file mode 100644 index 0000000000..70db3549cd --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/initializer/index.tsx @@ -0,0 +1,65 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import React from 'react'; +import { + SchemaInitializerActionModal, + SchemaInitializerItemType, + SelectProps, + useCollection, + useCompile, + useSchemaInitializer, +} from '@nocobase/client'; +import { MenuOutlined } from '@ant-design/icons'; + +import { FieldNameLowercase } from '../constants'; +import { useT } from '../locale'; +import { getOrderDetailsSchema } from '../schema'; + +export function useFieldOptions(): SelectProps['options'] { + const collection = useCollection(); + + const compile = useCompile(); + return collection + .getFields() + .map((field) => ({ label: field.uiSchema?.title ? compile(field.uiSchema.title) : field.name, value: field.name })); +} + +const OrderDetailsSchemaInitializer = () => { + const t = useT(); + const { insert } = useSchemaInitializer(); + const options = useFieldOptions(); + + return ( + } + isItem + onSubmit={({ orderField }) => { + insert(getOrderDetailsSchema(orderField)); + }} + schema={{ + orderField: { + type: 'string', + title: t('Order field'), + required: true, + 'x-component': 'Select', + 'x-decorator': 'FormItem', + enum: options, + }, + }} + > + ); +}; + +export const orderDetailsInitializerItem: SchemaInitializerItemType = { + name: FieldNameLowercase, + Component: OrderDetailsSchemaInitializer, +}; diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/locale.ts b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/locale.ts new file mode 100644 index 0000000000..84797b7d1b --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/locale.ts @@ -0,0 +1,21 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +// @ts-ignore +import pkg from './../../package.json'; +import { useApp } from '@nocobase/client'; + +export function useT() { + const app = useApp(); + return (str: string) => app.i18n.t(str, { ns: [pkg.name, 'client'] }); +} + +export function tStr(key: string) { + return `{{t(${JSON.stringify(key)}, { ns: ['${pkg.name}', 'client'], nsMode: 'fallback' })}}`; +} diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/schema/index.ts b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/schema/index.ts new file mode 100644 index 0000000000..7313a654c0 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/schema/index.ts @@ -0,0 +1,23 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { ISchema } from '@nocobase/client'; +import { FieldComponentName } from '../constants'; +import { orderDetailsSettings } from '../settings'; + +export const getOrderDetailsSchema = (orderField: string): ISchema => ({ + type: 'void', + 'x-decorator': 'FormItem', + 'x-toolbar': 'FormItemSchemaToolbar', + 'x-component': FieldComponentName, + 'x-component-props': { + orderField: orderField, + }, + 'x-settings': orderDetailsSettings.name, +}); diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/settings/index.ts b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/settings/index.ts new file mode 100644 index 0000000000..c9741be6df --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/settings/index.ts @@ -0,0 +1,29 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { SchemaSettings } from '@nocobase/client'; +import { FieldNameLowercase } from '../constants'; +import { orderFieldSchemaSettingsItem } from './items/orderField'; + +export const orderDetailsSettings = new SchemaSettings({ + name: `blockSettings:${FieldNameLowercase}`, + items: [ + orderFieldSchemaSettingsItem, + { + name: 'remove', + type: 'remove', + componentProps: { + removeParentsIfNoChildren: true, + breakRemoveOn: { + 'x-component': 'Grid', + }, + }, + }, + ], +}); diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/settings/items/orderField.ts b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/settings/items/orderField.ts new file mode 100644 index 0000000000..adc46de80f --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/client/settings/items/orderField.ts @@ -0,0 +1,19 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { createSelectSchemaSettingsItem } from '@nocobase/client'; +import { tStr } from '../../locale'; +import { useFieldOptions } from '../../initializer'; + +export const orderFieldSchemaSettingsItem = createSelectSchemaSettingsItem({ + name: 'orderField', + title: tStr('Order field'), + useOptions: useFieldOptions, + schemaKey: `x-component-props.orderField`, +}); diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/index.ts b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/index.ts new file mode 100644 index 0000000000..be99a2ff1a --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/index.ts @@ -0,0 +1,11 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +export * from './server'; +export { default } from './server'; diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/locale/en-US.json b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/locale/en-US.json new file mode 100644 index 0000000000..0dda81788d --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/locale/en-US.json @@ -0,0 +1,5 @@ +{ + "Order Details": "Order Details", + "Order field": "Order field", + "Select Order Field": "Select Order Field" +} \ No newline at end of file diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/locale/zh-CN.json b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/locale/zh-CN.json new file mode 100644 index 0000000000..733c3bcca2 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/locale/zh-CN.json @@ -0,0 +1,5 @@ +{ + "Order Details": "订单详情", + "Order field": "订单字段", + "Select Order Field": "选择订单字段" +} \ No newline at end of file diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/server/collections/.gitkeep b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/server/collections/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/server/index.ts b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/server/index.ts new file mode 100644 index 0000000000..be989de7c3 --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/server/index.ts @@ -0,0 +1,10 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +export { default } from './plugin'; diff --git a/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/server/plugin.ts b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/server/plugin.ts new file mode 100644 index 0000000000..38bb049c0d --- /dev/null +++ b/packages/plugins/@nocobase-sample/plugin-field-component-without-value/src/server/plugin.ts @@ -0,0 +1,28 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { Plugin } from '@nocobase/server'; + +export class PluginFieldComponentWithoutValueServer extends Plugin { + async afterAdd() {} + + async beforeLoad() {} + + async load() {} + + async install() {} + + async afterEnable() {} + + async afterDisable() {} + + async remove() {} +} + +export default PluginFieldComponentWithoutValueServer; diff --git a/yarn.lock b/yarn.lock index 6341c6bc6c..18b32a66cb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -234,13 +234,13 @@ rc-util "^5.31.1" "@ant-design/icons@^5.x": - version "5.3.7" - resolved "https://registry.npmmirror.com/@ant-design/icons/-/icons-5.3.7.tgz#d9f3654bf7934ee5faba43f91b5a187f5309ec68" - integrity sha512-bCPXTAg66f5bdccM4TT21SQBDO1Ek2gho9h3nO9DAKXJP4sq+5VBjrQMSxMVXSB3HyEz+cUbHQ5+6ogxCOpaew== + version "5.4.0" + resolved "https://registry.npmmirror.com/@ant-design/icons/-/icons-5.4.0.tgz#4bd8f335c68207cc06fe9943d164a81cdfcfbeac" + integrity sha512-QZbWC5xQYexCI5q4/fehSEkchJr5UGtvAJweT743qKUQQGs9IH2DehNLP49DJ3Ii9m9CijD2HN6fNy3WKhIFdA== dependencies: "@ant-design/colors" "^7.0.0" "@ant-design/icons-svg" "^4.4.0" - "@babel/runtime" "^7.11.2" + "@babel/runtime" "^7.24.8" classnames "^2.2.6" rc-util "^5.31.1" @@ -2603,7 +2603,14 @@ dependencies: regenerator-runtime "^0.14.0" -"@babel/template@^7.22.15", "@babel/template@^7.3.3": +"@babel/runtime@^7.24.8": + version "7.25.0" + resolved "https://registry.npmmirror.com/@babel/runtime/-/runtime-7.25.0.tgz#3af9a91c1b739c569d5d80cc917280919c544ecb" + integrity sha512-7dRy4DwXwtzBrPbZflqxnvfxLF8kdZXPkhymtDeFoFqE6ldzjQFgYTtYIFARcLEYDrqfBfYcZt1WqFxRoyC9Rw== + dependencies: + regenerator-runtime "^0.14.0" + +"@babel/template@^7.22.15", "@babel/template@^7.22.5", "@babel/template@^7.3.3": version "7.22.15" resolved "https://registry.npmmirror.com/@babel/template/-/template-7.22.15.tgz#09576efc3830f0430f4548ef971dde1350ef2f38" integrity sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==