创建菜单的匹配规则添加 “组模式”

This commit is contained in:
icssoa 2023-03-16 16:24:43 +08:00
parent 622a69a729
commit b4886a77e4
6 changed files with 134 additions and 47 deletions

View File

@ -9,7 +9,7 @@
"lint:eslint": "eslint \"{src}/**/*.{vue,ts,tsx}\" --fix" "lint:eslint": "eslint \"{src}/**/*.{vue,ts,tsx}\" --fix"
}, },
"dependencies": { "dependencies": {
"@cool-vue/crud": "^6.1.10", "@cool-vue/crud": "^6.1.11",
"@element-plus/icons-vue": "^2.0.10", "@element-plus/icons-vue": "^2.0.10",
"@vueuse/core": "^9.1.0", "@vueuse/core": "^9.1.0",
"@wangeditor/editor": "^5.1.23", "@wangeditor/editor": "^5.1.23",

View File

@ -1,3 +1,5 @@
import { Merge } from "/@/cool";
export const Colors = [ export const Colors = [
"#409EFF", "#409EFF",
"#67C23A", "#67C23A",
@ -11,7 +13,52 @@ export const Colors = [
"#FB78F2" "#FB78F2"
]; ];
export const PropRules = [ export const PropRules: {
test?: any[];
group?: string[];
table?: Merge<
DeepPartial<ClTable.Column>,
{
name?: string;
props?: {
[key: string]: any;
};
}
>;
form?: ClForm.Item;
handler?: string;
order?: number;
}[] = [
{
group: ["province", "city", "district"],
table: {
label: "省市区",
formatter(row) {
return row.province + "-" + row.city + "-" + row.district;
}
},
form: {
label: "省市区",
prop: "pca",
hook: "pca",
component: {
name: "cl-distpicker"
}
}
},
{
test: ["address", "addr"],
table: {
showOverflowTooltip: true
},
form: {
name: "el-input",
props: {
type: "textarea",
rows: 3
}
}
},
{ {
test: ["createTime"], test: ["createTime"],
table: { table: {
@ -105,12 +152,10 @@ export const PropRules = [
} }
}, },
form: { form: {
component: { name: "el-date-picker",
name: "el-date-picker", props: {
props: { type: "daterange",
type: "daterange", valueFormat: "YYYY-MM-DD"
valueFormat: "YYYY-MM-DD"
}
} }
} }
}, },
@ -118,13 +163,11 @@ export const PropRules = [
{ {
test: ["times", "timeRange", "timeScope"], test: ["times", "timeRange", "timeScope"],
form: { form: {
component: { name: "el-date-picker",
name: "el-date-picker", props: {
props: { type: "datetimerange",
type: "datetimerange", valueFormat: "YYYY-MM-DD HH:mm:ss",
valueFormat: "YYYY-MM-DD HH:mm:ss", defaultTime: [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]
defaultTime: [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]
}
} }
} }
}, },
@ -167,12 +210,14 @@ export const PropRules = [
{ {
test: ["num", "price", "age", "amount", "stock"], test: ["num", "price", "age", "amount", "stock"],
form: { form: {
name: "el-input-number",
hook: { hook: {
bind: ["number"] bind: ["number"]
}, },
props: { component: {
min: 0 name: "el-input-number",
props: {
min: 0
}
} }
} }
}, },

View File

@ -101,10 +101,7 @@ export function useChatGPT() {
// 发送 // 发送
function send(data: { name: string; columns: string[]; module: string }) { function send(data: { name: string; columns: string[]; module: string }) {
socket?.emit("data", { socket?.emit("data", data);
...data,
apiKey: apiKey.value
});
} }
return { return {

View File

@ -1,7 +1,7 @@
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { last } from "lodash-es"; import { last } from "lodash-es";
import { MenuData } from "../types"; import { MenuData } from "../types";
import { createComponent } from "../utils"; import { createComponent, toCodeString } from "../utils";
import { service } from "/@/cool"; import { service } from "/@/cool";
export function useCode() { export function useCode() {
@ -20,7 +20,12 @@ export function useCode() {
// 遍历 // 遍历
columns.forEach((e) => { columns.forEach((e) => {
// 组件 // 组件
const { item, column } = createComponent(e); const { item, column, isHidden } = createComponent(e, columns);
// 过滤隐藏
if (isHidden) {
return false;
}
// 验证规则 // 验证规则
if (!e.nullable) { if (!e.nullable) {
@ -165,10 +170,10 @@ export function useCode() {
const { service } = useCool(); const { service } = useCool();
// cl-upsert // cl-upsert
const Upsert = useUpsert(${JSON.stringify(upsert)}); const Upsert = useUpsert(${toCodeString(upsert)});
// cl-table // cl-table
const Table = useTable(${JSON.stringify(table)}); const Table = useTable(${toCodeString(table)});
// cl-crud // cl-crud
const Crud = useCrud( const Crud = useCrud(

View File

@ -80,32 +80,50 @@ const handler = {
}; };
// 创建组件 // 创建组件
export function createComponent(entity: Entity) { export function createComponent(entity: Entity, columns: Entity[]) {
const prop = entity.propertyName; const prop = entity.propertyName;
let label = entity.comment; let label = entity.comment;
let d: any; let d: any;
let isHidden = false;
PropRules.find((r) => { PropRules.find((r) => {
const s = r.test.find((e) => { let s = false;
if (isRegExp(e)) {
return e.test(prop);
}
if (isFunction(e)) { if (r.test) {
return e(prop); s = !!r.test.find((e) => {
} if (isRegExp(e)) {
return e.test(prop);
if (isString(e)) {
if (e == prop) {
return true;
} }
const re = new RegExp(`${e}$`); if (isFunction(e)) {
return re.test(prop.toLocaleLowerCase()); return e(prop);
} }
return false; if (isString(e)) {
}); if (e == prop) {
return true;
}
const re = new RegExp(`${e}$`);
return re.test(prop.toLocaleLowerCase());
}
return false;
});
}
if (r.group) {
if (
r.group.includes(prop) &&
r.group.some((e) => columns.find((c) => c.propertyName == e))
) {
if (r.group[0] == prop) {
s = true;
} else {
isHidden = true;
}
}
}
if (s) { if (s) {
if (r.handler) { if (r.handler) {
@ -122,7 +140,7 @@ export function createComponent(entity: Entity) {
} }
} }
return !!s; return s;
}); });
function parse(v: any) { function parse(v: any) {
@ -145,6 +163,28 @@ export function createComponent(entity: Entity) {
return { return {
column: parse(d?.table), column: parse(d?.table),
item: parse(d?.form) item: parse(d?.form),
isHidden
}; };
} }
// 转成代码字符串
export function toCodeString(data: any) {
const arr: string[][] = [];
let code = JSON.stringify(data, (key, value) => {
if (isFunction(value)) {
const str = value.toString();
arr.push([JSON.stringify({ [key]: str }), str]);
return str;
} else {
return value;
}
});
arr.forEach((e) => {
code = code.replace(e[0].substring(1, e[0].length - 1), e[1]);
});
return code;
}

View File

@ -36,7 +36,7 @@
/> />
</div> </div>
<div class="label">Key</div> <!-- <div class="label">Key</div>
<div class="row"> <div class="row">
<el-input <el-input
@ -58,7 +58,7 @@
<Refresh /> <Refresh />
</el-icon> </el-icon>
</el-button> </el-button>
</div> </div> -->
<div class="label">其他你想做的事</div> <div class="label">其他你想做的事</div>