diff --git a/package.json b/package.json index 3ca95a9..9e6112c 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "lint:eslint": "eslint \"{src}/**/*.{vue,ts,tsx}\" --fix" }, "dependencies": { - "@cool-vue/crud": "^7.0.0-beta9", + "@cool-vue/crud": "^7.0.1-beta1", "@element-plus/icons-vue": "^2.1.0", "@vueuse/core": "^10.4.0", "@wangeditor/editor": "^5.1.23", diff --git a/packages/crud/package.json b/packages/crud/package.json index c91bc93..fc95190 100644 --- a/packages/crud/package.json +++ b/packages/crud/package.json @@ -1,6 +1,6 @@ { "name": "@cool-vue/crud", - "version": "7.0.1", + "version": "7.0.1-beta2", "private": false, "main": "./dist/index.umd.min.js", "typings": "types/index.d.ts", diff --git a/packages/crud/src/hooks/crud.ts b/packages/crud/src/hooks/crud.ts index a4155b0..3a821d1 100644 --- a/packages/crud/src/hooks/crud.ts +++ b/packages/crud/src/hooks/crud.ts @@ -1,3 +1,4 @@ +import { TestService } from "../test/service"; import { watch, ref, nextTick, getCurrentInstance, Ref, inject, provide } from "vue"; // 获取上级 @@ -56,6 +57,11 @@ export function useCrud(options?: DeepPartial, cb?: (app: ClCrud useParent("cl-crud", Crud); if (options) { + // 测试模式 + if (options.service == "test") { + options.service = new TestService(); + } + provide("useCrud__options", options); } diff --git a/packages/crud/src/test/service.ts b/packages/crud/src/test/service.ts new file mode 100644 index 0000000..0c11aa8 --- /dev/null +++ b/packages/crud/src/test/service.ts @@ -0,0 +1,190 @@ +import { orderBy } from "lodash-es"; +import { uuid } from "../utils"; + +const userList = [ + { + id: "110000199206102819", + name: "楚行云", + createTime: "1996-09-14", + wages: 73026, + status: 1, + account: "ihknssft", + occupation: 4, + phone: 13797353874 + }, + { + id: "410000199208224044", + name: "秦尘", + createTime: "1977-11-09", + wages: 74520, + status: 0, + account: "xlabchey", + occupation: 3, + phone: 18593911044 + }, + { + id: "120000199708139664", + name: "叶凡", + createTime: "1982-11-28", + wages: 81420, + status: 0, + account: "xpqbtkul", + occupation: 1, + phone: 16234136338 + }, + { + id: "710000200203060278", + name: "白小纯", + createTime: "2012-12-17", + wages: 65197, + status: 1, + account: "kirukkje", + occupation: 2, + phone: 16325661110 + }, + { + id: "210000201007157714", + name: "韩立", + createTime: "1982-07-10", + wages: 99107, + status: 1, + account: "rbrohvoj", + occupation: 2, + phone: 18486594866 + }, + { + id: "420000200901038044", + name: "唐三", + createTime: "2019-07-31", + wages: 80658, + status: 1, + account: "qtuwsfuh", + occupation: 5, + phone: 15565014642 + }, + { + id: "150000197711136225", + name: "王林", + createTime: "2009-07-26", + wages: 57408, + status: 1, + account: "gxyhlwdq", + occupation: 1, + phone: 13852767084 + }, + { + id: "710000198106232170", + name: "李强", + createTime: "2016-04-26", + wages: 71782, + status: 1, + account: "vruiimiy", + occupation: 3, + phone: 18365332834 + }, + { + id: "530000199311309764", + name: "秦羽", + createTime: "1984-01-18", + wages: 87860, + status: 1, + account: "dtvkpyag", + occupation: 0, + phone: 18149247129 + } +]; + +class TestService { + // 分页列表 + async page(params: any) { + const { status, occupation, keyWord, page, size, phone, name, sort, order } = params || {}; + + // 过滤后的列表 + const list = orderBy(userList, order, sort).filter((e) => { + if (status !== undefined) { + return e.status == status; + } + + if (phone !== undefined) { + return String(e.phone).includes(phone); + } + + if (name !== undefined) { + return e.name.includes(name); + } + + if (keyWord !== undefined) { + return e.name.includes(keyWord) || String(e.phone).includes(keyWord); + } + + if (occupation !== undefined) { + return e.occupation == occupation; + } + + return true; + }); + + return new Promise((resolve) => { + // 模拟延迟 + setTimeout(() => { + resolve({ + list: list.slice((page - 1) * size, page * size), + pagination: { + total: list.length, + page, + size + }, + subData: { + wages: list.reduce((a, b) => { + return a + b.wages; + }, 0) + } + }); + }, 500); + }); + } + + // 更新 + async update(params: { id: any; [key: string]: any }) { + const item = userList.find((e) => e.id == params.id); + + if (item) { + Object.assign(item, params); + } + } + + // 新增 + async add(params: any) { + const id = uuid(); + + userList.push({ + id, + ...params + }); + + return id; + } + + // 详情 + async info(params: { id: any }) { + const { id } = params || {}; + return userList.find((e) => e.id == id); + } + + // 删除 + async delete(params: { ids: any[] }) { + const { ids = [] } = params || {}; + + ids.forEach((id) => { + const index = userList.findIndex((e) => e.id == id); + userList.splice(index, 1); + }); + } + + // 全部列表 + async list() { + return userList; + } +} + +export { TestService }; diff --git a/packages/crud/src/utils/index.ts b/packages/crud/src/utils/index.ts index bc81f72..ecc93a3 100644 --- a/packages/crud/src/utils/index.ts +++ b/packages/crud/src/utils/index.ts @@ -132,3 +132,17 @@ export function deepFind(value: any, list: any[]) { return deep(list); } + +// uuid +export function uuid(separator = "-"): string { + const s: any[] = []; + const hexDigits = "0123456789abcdef"; + for (let i = 0; i < 36; i++) { + s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); + } + s[14] = "4"; + s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); + s[8] = s[13] = s[18] = s[23] = separator; + + return s.join(""); +} diff --git a/packages/crud/types/components/adv/search.d.ts b/packages/crud/types/components/adv/search.d.ts index e1708c3..c2bc7e4 100644 --- a/packages/crud/types/components/adv/search.d.ts +++ b/packages/crud/types/components/adv/search.d.ts @@ -34,8 +34,8 @@ declare const _default: import("vue").DefineComponent<{ onReset?: ((...args: any[]) => any) | undefined; onClear?: ((...args: any[]) => any) | undefined; }, { + size: string | number; items: ClForm.Item[]; op: unknown[]; - size: string | number; }, {}>; export default _default; diff --git a/packages/crud/types/components/table/helper/index.d.ts b/packages/crud/types/components/table/helper/index.d.ts index dec9346..9112c47 100644 --- a/packages/crud/types/components/table/helper/index.d.ts +++ b/packages/crud/types/components/table/helper/index.d.ts @@ -80,7 +80,7 @@ export declare function useTable(props: any): { column: any; $index: number; }) => any; - sortable: boolean | "desc" | "asc" | "custom" | "descending" | "ascending"; + sortable: boolean | "asc" | "desc" | "custom" | "descending" | "ascending"; sortMethod: fn; sortBy: string | any[] | ((row: any, index: number) => any); resizable: boolean; diff --git a/packages/crud/types/test/service.d.ts b/packages/crud/types/test/service.d.ts new file mode 100644 index 0000000..1867d04 --- /dev/null +++ b/packages/crud/types/test/service.d.ts @@ -0,0 +1,34 @@ +declare class TestService { + page(params: any): Promise; + update(params: { + id: any; + [key: string]: any; + }): Promise; + add(params: any): Promise; + info(params: { + id: any; + }): Promise<{ + id: string; + name: string; + createTime: string; + wages: number; + status: number; + account: string; + occupation: number; + phone: number; + } | undefined>; + delete(params: { + ids: any[]; + }): Promise; + list(): Promise<{ + id: string; + name: string; + createTime: string; + wages: number; + status: number; + account: string; + occupation: number; + phone: number; + }[]>; +} +export { TestService }; diff --git a/packages/crud/types/utils/index.d.ts b/packages/crud/types/utils/index.d.ts index c31696b..f07c218 100644 --- a/packages/crud/types/utils/index.d.ts +++ b/packages/crud/types/utils/index.d.ts @@ -8,3 +8,4 @@ export declare function addClass(el: Element, name: string): void; export declare function removeClass(el: Element, name: string): void; export declare function getValue(data: any, params?: any): any; export declare function deepFind(value: any, list: any[]): any; +export declare function uuid(separator?: string): string; diff --git a/src/cool/service/request.ts b/src/cool/service/request.ts index 653e906..b1edd93 100644 --- a/src/cool/service/request.ts +++ b/src/cool/service/request.ts @@ -127,17 +127,13 @@ request.interceptors.response.use( NProgress.done(); if (error.response) { - const { status, config: c } = error.response; + const { status } = error.response; const { user } = useBase(); if (status == 401) { user.logout(); } else { - if (isDev) { - if (c.url != `${config.baseUrl}/`) { - ElMessage.error(`${c.url} ${status}`); - } - } else { + if (!isDev) { switch (status) { case 403: router.push("/403"); diff --git a/src/modules/base/pages/login/components/pic-captcha.vue b/src/modules/base/pages/login/components/pic-captcha.vue index 4d63f39..04bd54a 100644 --- a/src/modules/base/pages/login/components/pic-captcha.vue +++ b/src/modules/base/pages/login/components/pic-captcha.vue @@ -1,13 +1,20 @@ diff --git a/src/modules/magic/hooks/ai.ts b/src/modules/magic/hooks/ai.ts index 4dcb3d3..df8d6b1 100644 --- a/src/modules/magic/hooks/ai.ts +++ b/src/modules/magic/hooks/ai.ts @@ -1,7 +1,6 @@ import { ElNotification } from "element-plus"; import { io, Socket } from "socket.io-client"; import { useCool } from "/@/cool"; -import { isString } from "lodash-es"; export function useAi() { const { route, router } = useCool(); @@ -11,7 +10,7 @@ export function useAi() { // 连接 function connect(cb: { onMessage?(content: string): void; onComplete?(): void }) { if (!socket) { - socket = io("http://192.168.0.224:9009/code", { + socket = io("https://service.cool-js.com/code", { transports: ["websocket"] }); diff --git a/src/modules/upload/components/upload.vue b/src/modules/upload/components/upload.vue index 6d070f2..5632452 100644 --- a/src/modules/upload/components/upload.vue +++ b/src/modules/upload/components/upload.vue @@ -291,7 +291,8 @@ async function onBeforeUpload(file: any, item?: Upload.Item) { type: getType(file.name), progress: 0, url: "", - preload: "" + preload: "", + error: "" }; // 图片预览地址 diff --git a/yarn.lock b/yarn.lock index 3d5fa83..82a001f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -282,10 +282,10 @@ "@babel/helper-validator-identifier" "^7.22.20" to-fast-properties "^2.0.0" -"@cool-vue/crud@^7.0.0-beta9": - version "7.0.0-beta9" - resolved "https://registry.yarnpkg.com/@cool-vue/crud/-/crud-7.0.0-beta9.tgz#4ce18b4f10a0deaf7715febfef88d0e068c615ba" - integrity sha512-uVBw7abKzkoZ3Q+VAQ2xVhMzScdjpwgbpcBVaNNj2zChELfsfmaxcFT19KLjdKmAyOtWE0+aMbj5/jyQPcJLnA== +"@cool-vue/crud@^7.0.1-beta1": + version "7.0.1-beta1" + resolved "https://registry.yarnpkg.com/@cool-vue/crud/-/crud-7.0.1-beta1.tgz#74f74b2c2604bfb3a006fe19dfe96aee389ce21e" + integrity sha512-69QaNJ6I+Ha4bYo5vZiMpbb0z2q6hPbR/G997WIhXdLYDfwhRjrjpB2PnH1JIXMo00iuC5DJS01QdYBpXxVHFw== dependencies: array.prototype.flat "^1.2.4" core-js "^3.21.1"