This commit is contained in:
神仙都没用 2023-09-28 16:10:44 +08:00
parent 1735d6258e
commit 8ce4c5047e
20 changed files with 370 additions and 28 deletions

View File

@ -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",

View File

@ -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",

View File

@ -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<ClCrud.Options>, cb?: (app: ClCrud
useParent("cl-crud", Crud);
if (options) {
// 测试模式
if (options.service == "test") {
options.service = new TestService();
}
provide("useCrud__options", options);
}

View File

@ -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 };

View File

@ -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("");
}

View File

@ -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;

View File

@ -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;

34
packages/crud/types/test/service.d.ts vendored Normal file
View File

@ -0,0 +1,34 @@
declare class TestService {
page(params: any): Promise<unknown>;
update(params: {
id: any;
[key: string]: any;
}): Promise<void>;
add(params: any): Promise<string>;
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<void>;
list(): Promise<{
id: string;
name: string;
createTime: string;
wages: number;
status: number;
account: string;
occupation: number;
phone: number;
}[]>;
}
export { TestService };

View File

@ -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;

View File

@ -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");

View File

@ -1,13 +1,20 @@
<template>
<div class="pic-captcha" @click="refresh">
<div v-if="svg" class="svg" v-html="svg" />
<img v-else class="base64" :src="base64" alt="" />
<img v-else-if="base64" class="base64" :src="base64" alt="" />
<template v-else>
<el-icon class="is-loading">
<Loading />
</el-icon>
</template>
</div>
</template>
<script lang="ts" setup>
import { onMounted, ref } from "vue";
import { ElMessage } from "element-plus";
import { Loading } from "@element-plus/icons-vue";
import { useCool } from "/@/cool";
const emit = defineEmits(["update:modelValue", "change"]);
@ -20,8 +27,8 @@ const base64 = ref("");
// svg
const svg = ref("");
function refresh() {
service.base.open
async function refresh() {
await service.base.open
.captcha({
height: 45,
width: 150,
@ -57,9 +64,13 @@ defineExpose({
<style lang="scss" scoped>
.pic-captcha {
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
height: 45px;
width: 150px;
position: relative;
.svg {
height: 100%;
@ -69,5 +80,11 @@ defineExpose({
.base64 {
height: 100%;
}
.el-icon {
position: absolute;
font-size: 22px;
right: 20px;
}
}
</style>

View File

@ -125,11 +125,15 @@ async function toLogin() {
//
storage.set("username", form.username);
//
//
router.push("/");
} catch (err: any) {
} catch (err) {
//
refs.picCaptcha.refresh();
ElMessage.error(err.message);
if (err instanceof Error) {
ElMessage.error(err.message);
}
}
saving.value = false;

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -1 +1,29 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1695872084016" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3043" xmlns:xlink="http://www.w3.org/1999/xlink" width="64" height="64"><path d="M853.333333 85.333333H170.666667a86.570667 86.570667 0 0 0-85.333334 85.333334v682.666666a85.717333 85.717333 0 0 0 85.333334 85.333334h682.666666a86.186667 86.186667 0 0 0 85.333334-85.333334V170.666667a85.333333 85.333333 0 0 0-85.333334-85.333334zM170.666667 853.333333V170.666667h682.666666v682.666666z" fill="#2c2c2c" p-id="3044"></path><path d="M387.2 379.733333a61.781333 61.781333 0 0 1 61.781333-61.781333h19.114667a30.890667 30.890667 0 0 0 0-61.781333h-19.114667a123.733333 123.733333 0 0 0-123.733333 123.733333v304.512a30.890667 30.890667 0 1 0 61.781333 0z" fill="#2c2c2c" p-id="3045"></path><path d="M261.76 429.610667h217.728a27.392 27.392 0 0 1 31.146667 30.890666 27.392 27.392 0 0 1-31.146667 30.890667h-217.6a27.434667 27.434667 0 0 1-31.146667-30.890667 27.392 27.392 0 0 1 31.146667-30.890666z" fill="#2c2c2c" p-id="3046"></path><path d="M737.322667 331.008a30.890667 30.890667 0 0 0-26.88 15.445333l-61.781334 108.117334-61.781333-108.117334a30.890667 30.890667 0 1 0-53.461333 30.890667l80.341333 139.008-80.341333 139.008a30.890667 30.890667 0 1 0 53.461333 30.890667l61.781333-108.117334 61.781334 108.117334a30.890667 30.890667 0 1 0 53.461333-30.890667l-80.341333-139.008 80.341333-139.008a30.890667 30.890667 0 0 0-26.581333-46.336z" fill="#2c2c2c" p-id="3047"></path></svg>
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg
t="1695872084016"
class="icon"
viewBox="0 0 1024 1024"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
p-id="3043"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="64"
height="64"
>
<path
d="M853.333333 85.333333H170.666667a86.570667 86.570667 0 0 0-85.333334 85.333334v682.666666a85.717333 85.717333 0 0 0 85.333334 85.333334h682.666666a86.186667 86.186667 0 0 0 85.333334-85.333334V170.666667a85.333333 85.333333 0 0 0-85.333334-85.333334zM170.666667 853.333333V170.666667h682.666666v682.666666z"
p-id="3044"
></path>
<path
d="M387.2 379.733333a61.781333 61.781333 0 0 1 61.781333-61.781333h19.114667a30.890667 30.890667 0 0 0 0-61.781333h-19.114667a123.733333 123.733333 0 0 0-123.733333 123.733333v304.512a30.890667 30.890667 0 1 0 61.781333 0z"
p-id="3045"
></path>
<path
d="M261.76 429.610667h217.728a27.392 27.392 0 0 1 31.146667 30.890666 27.392 27.392 0 0 1-31.146667 30.890667h-217.6a27.434667 27.434667 0 0 1-31.146667-30.890667 27.392 27.392 0 0 1 31.146667-30.890666z"
p-id="3046"
></path>
<path
d="M737.322667 331.008a30.890667 30.890667 0 0 0-26.88 15.445333l-61.781334 108.117334-61.781333-108.117334a30.890667 30.890667 0 1 0-53.461333 30.890667l80.341333 139.008-80.341333 139.008a30.890667 30.890667 0 1 0 53.461333 30.890667l61.781333-108.117334 61.781334 108.117334a30.890667 30.890667 0 1 0 53.461333-30.890667l-80.341333-139.008 80.341333-139.008a30.890667 30.890667 0 0 0-26.581333-46.336z"
p-id="3047"
></path>
</svg>

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -1 +1,21 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1695872076721" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2736" xmlns:xlink="http://www.w3.org/1999/xlink" width="64" height="64"><path d="M860.665625 73.54166667H166.2875c-50.6953125 0-91.74375 41.0484375-91.74375 91.74375v694.2796875c0 50.6953125 41.0484375 91.74375 91.74375 91.74375h694.2796875c50.6953125 0 91.74375-41.0484375 91.74375-91.74375V165.18697917c0-50.596875-41.0484375-91.6453125-91.6453125-91.6453125zM743.721875 95.29635417c82.884375 0 150.01875 67.134375 150.01875 150.01875 0 101.784375-86.3296875 169.2140625-143.325 242.746875-1.4765625 1.96875-2.953125 3.8390625-4.4296875 5.8078125 3.740625-5.11875-26.8734375-33.7640625-30.7125-37.8984375C660.640625 397.00729167 593.703125 331.64479167 593.703125 245.31510417c-0.0984375-82.884375 67.134375-150.01875 150.01875-150.01875z m175.3171875 407.53125L719.6046875 714.36979167l143.71875 140.8640625c8.071875 7.875 8.1703125 20.7703125 0.2953125 28.8421875-4.0359375 4.0359375-9.253125 6.103125-14.56875 6.103125-5.11875 0-10.3359375-1.96875-14.2734375-5.8078125L537.790625 593.29166667 287.6609375 858.48229167c-4.0359375 4.2328125-9.45 6.3984375-14.8640625 6.3984375-5.0203125 0-10.040625-1.8703125-13.978125-5.5125-8.1703125-7.678125-8.5640625-20.5734375-0.8859375-28.8421875l250.7203125-265.78125-124.228125-121.7671875-192.740625 204.35625c-4.0359375 4.2328125-9.45 6.3984375-14.8640625 6.3984375-5.0203125 0-10.040625-1.8703125-13.978125-5.5125-8.1703125-7.678125-8.5640625-20.5734375-0.8859375-28.8421875l193.2328125-204.946875-191.559375-187.7203125c-8.071875-7.875-8.1703125-20.7703125-0.2953125-28.8421875s20.7703125-8.1703125 28.8421875-0.2953125l344.53125 337.5421875 62.015625-65.75625c7.678125-8.1703125 20.5734375-8.5640625 28.8421875-0.8859375 8.1703125 7.678125 8.5640625 20.5734375 0.8859375 28.8421875l-62.5078125 66.2484375L690.4671875 685.82291667l198.9421875-210.9515625c7.678125-8.1703125 20.5734375-8.5640625 28.8421875-0.8859375 8.1703125 7.7765625 8.5640625 20.671875 0.7875 28.8421875z" fill="#2c2c2c" p-id="2737"></path><path d="M743.721875 231.82916667m-78.35625 0a78.35625 78.35625 0 1 0 156.7125 0 78.35625 78.35625 0 1 0-156.7125 0Z" fill="#2c2c2c" p-id="2738"></path></svg>
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg
t="1695872076721"
class="icon"
viewBox="0 0 1024 1024"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
p-id="2736"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="64"
height="64"
>
<path
d="M860.665625 73.54166667H166.2875c-50.6953125 0-91.74375 41.0484375-91.74375 91.74375v694.2796875c0 50.6953125 41.0484375 91.74375 91.74375 91.74375h694.2796875c50.6953125 0 91.74375-41.0484375 91.74375-91.74375V165.18697917c0-50.596875-41.0484375-91.6453125-91.6453125-91.6453125zM743.721875 95.29635417c82.884375 0 150.01875 67.134375 150.01875 150.01875 0 101.784375-86.3296875 169.2140625-143.325 242.746875-1.4765625 1.96875-2.953125 3.8390625-4.4296875 5.8078125 3.740625-5.11875-26.8734375-33.7640625-30.7125-37.8984375C660.640625 397.00729167 593.703125 331.64479167 593.703125 245.31510417c-0.0984375-82.884375 67.134375-150.01875 150.01875-150.01875z m175.3171875 407.53125L719.6046875 714.36979167l143.71875 140.8640625c8.071875 7.875 8.1703125 20.7703125 0.2953125 28.8421875-4.0359375 4.0359375-9.253125 6.103125-14.56875 6.103125-5.11875 0-10.3359375-1.96875-14.2734375-5.8078125L537.790625 593.29166667 287.6609375 858.48229167c-4.0359375 4.2328125-9.45 6.3984375-14.8640625 6.3984375-5.0203125 0-10.040625-1.8703125-13.978125-5.5125-8.1703125-7.678125-8.5640625-20.5734375-0.8859375-28.8421875l250.7203125-265.78125-124.228125-121.7671875-192.740625 204.35625c-4.0359375 4.2328125-9.45 6.3984375-14.8640625 6.3984375-5.0203125 0-10.040625-1.8703125-13.978125-5.5125-8.1703125-7.678125-8.5640625-20.5734375-0.8859375-28.8421875l193.2328125-204.946875-191.559375-187.7203125c-8.071875-7.875-8.1703125-20.7703125-0.2953125-28.8421875s20.7703125-8.1703125 28.8421875-0.2953125l344.53125 337.5421875 62.015625-65.75625c7.678125-8.1703125 20.5734375-8.5640625 28.8421875-0.8859375 8.1703125 7.678125 8.5640625 20.5734375 0.8859375 28.8421875l-62.5078125 66.2484375L690.4671875 685.82291667l198.9421875-210.9515625c7.678125-8.1703125 20.5734375-8.5640625 28.8421875-0.8859375 8.1703125 7.7765625 8.5640625 20.671875 0.7875 28.8421875z"
p-id="2737"
></path>
<path
d="M743.721875 231.82916667m-78.35625 0a78.35625 78.35625 0 1 0 156.7125 0 78.35625 78.35625 0 1 0-156.7125 0Z"
p-id="2738"
></path>
</svg>

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -5,7 +5,7 @@
<cl-add-btn />
<cl-multi-delete-btn />
<cl-flex1 />
<cl-search-key />
<cl-search-key placeholder="搜索名称" />
</cl-row>
<cl-row>

View File

@ -96,7 +96,7 @@
</template>
<script lang="tsx" name="demo-crud" setup>
import { useCrud, useUpsert, useTable, useAdvSearch, setFocus } from "@cool-vue/crud";
import { useCrud, useUpsert, useTable, useAdvSearch, setFocus, useSearch } from "@cool-vue/crud";
import { useDict } from "/$/dict";
import { reactive } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
@ -485,4 +485,20 @@ const AdvSearch = useAdvSearch({
}
]
});
//
const Search = useSearch({
items: [
{
label: "姓名",
prop: "name",
component: {
name: "el-input",
props: {
clearable: true
}
}
}
]
});
</script>

View File

@ -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"]
});

View File

@ -291,7 +291,8 @@ async function onBeforeUpload(file: any, item?: Upload.Item) {
type: getType(file.name),
progress: 0,
url: "",
preload: ""
preload: "",
error: ""
};
//

View File

@ -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"