mirror of
https://github.com/cool-team-official/cool-admin-vue.git
synced 2025-12-12 13:42:50 +00:00
优化,crud添加 prop 提示
This commit is contained in:
parent
06923e8990
commit
428f77220c
@ -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": "^7.1.0",
|
"@cool-vue/crud": "^7.1.3",
|
||||||
"@element-plus/icons-vue": "^2.1.0",
|
"@element-plus/icons-vue": "^2.1.0",
|
||||||
"@vueuse/core": "^10.4.0",
|
"@vueuse/core": "^10.4.0",
|
||||||
"@wangeditor/editor": "^5.1.23",
|
"@wangeditor/editor": "^5.1.23",
|
||||||
|
|||||||
7
packages/crud/index.d.ts
vendored
7
packages/crud/index.d.ts
vendored
@ -40,8 +40,8 @@ declare type obj = {
|
|||||||
declare type DeepPartial<T> = T extends Function
|
declare type DeepPartial<T> = T extends Function
|
||||||
? T
|
? T
|
||||||
: T extends object
|
: T extends object
|
||||||
? { [P in keyof T]?: DeepPartial<T[P]> }
|
? { [P in keyof T]?: DeepPartial<T[P]> }
|
||||||
: T;
|
: T;
|
||||||
|
|
||||||
// 合并
|
// 合并
|
||||||
declare type Merge<A, B> = Omit<A, keyof B> & B;
|
declare type Merge<A, B> = Omit<A, keyof B> & B;
|
||||||
@ -333,6 +333,7 @@ declare namespace ClTable {
|
|||||||
search: {
|
search: {
|
||||||
isInput: boolean;
|
isInput: boolean;
|
||||||
value: any;
|
value: any;
|
||||||
|
refreshOnChange: Boolean;
|
||||||
component: Render.Component;
|
component: Render.Component;
|
||||||
};
|
};
|
||||||
dict: DictOptions | Vue.Ref<DictOptions>;
|
dict: DictOptions | Vue.Ref<DictOptions>;
|
||||||
@ -626,7 +627,7 @@ declare namespace ClUpsert {
|
|||||||
mode: "add" | "update" | "info";
|
mode: "add" | "update" | "info";
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Options<T> extends DeepPartial<Config> {
|
interface Options<T = any> extends DeepPartial<Config<T>> {
|
||||||
items?: ClForm.Items<T>;
|
items?: ClForm.Items<T>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@cool-vue/crud",
|
"name": "@cool-vue/crud",
|
||||||
"version": "7.1.0",
|
"version": "7.1.3",
|
||||||
"private": false,
|
"private": false,
|
||||||
"main": "./dist/index.umd.min.js",
|
"main": "./dist/index.umd.min.js",
|
||||||
"typings": "types/index.d.ts",
|
"typings": "types/index.d.ts",
|
||||||
|
|||||||
@ -1,69 +1,23 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div>CRUD v7.0.0</div>
|
<div>CRUD DEMO v7.0.0</div>
|
||||||
|
|
||||||
<cl-crud>
|
<cl-crud>
|
||||||
<cl-add-btn />
|
<cl-add-btn />
|
||||||
|
|
||||||
<cl-upsert ref="Upsert"></cl-upsert>
|
<cl-upsert ref="Upsert"></cl-upsert>
|
||||||
</cl-crud>
|
</cl-crud>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="tsx">
|
||||||
import { ref } from "vue";
|
|
||||||
import { useTable, useForm, useSearch, useUpsert, useAdvSearch } from "./hooks";
|
import { useTable, useForm, useSearch, useUpsert, useAdvSearch } from "./hooks";
|
||||||
// Test
|
|
||||||
|
|
||||||
interface Data {
|
interface Data {
|
||||||
name?: string;
|
name?: string;
|
||||||
age?: number;
|
age?: number;
|
||||||
formatter?(): string;
|
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
type Form = {
|
|
||||||
data?: Data;
|
|
||||||
list?: Data[] | (() => any)[];
|
|
||||||
};
|
|
||||||
|
|
||||||
function useF<T>(options: Form): Form {
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
|
|
||||||
const form = useF({
|
|
||||||
list: [
|
|
||||||
{
|
|
||||||
name: "A"
|
|
||||||
},
|
|
||||||
() => {
|
|
||||||
return {
|
|
||||||
name: form.data?.age == 12 ? "A" : "B"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
const Table = useTable<Data>({
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
label: "xx",
|
|
||||||
prop: "a"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
const Form = useForm<Data>();
|
|
||||||
|
|
||||||
Form.value?.open({
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
type: "tabs",
|
|
||||||
prop: "age"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
const Upsert = useUpsert<Data>({
|
const Upsert = useUpsert<Data>({
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
@ -79,6 +33,32 @@ const Upsert = useUpsert<Data>({
|
|||||||
label: "x"
|
label: "x"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
onOpened(data) {}
|
||||||
|
});
|
||||||
|
|
||||||
|
const Table = useTable<Data>({
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
label: "xx",
|
||||||
|
prop: "a",
|
||||||
|
search: {
|
||||||
|
component: {
|
||||||
|
name: "el-date-picker"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
const Form = useForm<Data>();
|
||||||
|
|
||||||
|
Form.value?.open({
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
type: "tabs",
|
||||||
|
prop: "age"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -47,10 +47,13 @@ export function renderHeader(item: ClTable.Column, { scope, slots }: any) {
|
|||||||
item.search.value = val;
|
item.search.value = val;
|
||||||
},
|
},
|
||||||
onChange(val: any) {
|
onChange(val: any) {
|
||||||
crud.value?.refresh({
|
// 更改时刷新列表
|
||||||
page: 1,
|
if (item.search.refreshOnChange) {
|
||||||
[item.prop]: val === "" ? undefined : val
|
crud.value?.refresh({
|
||||||
});
|
page: 1,
|
||||||
|
[item.prop]: val === "" ? undefined : val
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -65,7 +65,7 @@ export function useCrud(options?: ClCrud.Options, cb?: (app: ClCrud.Ref) => void
|
|||||||
provide("useCrud__options", options);
|
provide("useCrud__options", options);
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(Crud, (val: any) => {
|
watch(Crud, (val) => {
|
||||||
if (val) {
|
if (val) {
|
||||||
if (cb) {
|
if (cb) {
|
||||||
cb(val);
|
cb(val);
|
||||||
@ -77,7 +77,7 @@ export function useCrud(options?: ClCrud.Options, cb?: (app: ClCrud.Ref) => void
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 新增、编辑
|
// 新增、编辑
|
||||||
export function useUpsert<T = any>(options?: ClUpsert.Options<T>): Ref<ClUpsert.Ref> {
|
export function useUpsert<T = any>(options?: ClUpsert.Options<T>) {
|
||||||
const Upsert = ref<ClUpsert.Ref>();
|
const Upsert = ref<ClUpsert.Ref>();
|
||||||
useParent("cl-upsert", Upsert);
|
useParent("cl-upsert", Upsert);
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ export function useUpsert<T = any>(options?: ClUpsert.Options<T>): Ref<ClUpsert.
|
|||||||
|
|
||||||
watch(
|
watch(
|
||||||
Upsert,
|
Upsert,
|
||||||
(val: any) => {
|
(val) => {
|
||||||
if (val) {
|
if (val) {
|
||||||
if (options) {
|
if (options) {
|
||||||
const event = useEvent(["onOpen", "onOpened", "onClosed"], {
|
const event = useEvent(["onOpen", "onOpened", "onClosed"], {
|
||||||
@ -105,7 +105,7 @@ export function useUpsert<T = any>(options?: ClUpsert.Options<T>): Ref<ClUpsert.
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return Upsert as Ref<ClUpsert.Ref<T>>;
|
return Upsert;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 表格
|
// 表格
|
||||||
@ -164,7 +164,7 @@ export function useDialog(options?: { onFullscreen(visible: boolean): void }) {
|
|||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => Dialog?.fullscreen.value,
|
() => Dialog?.fullscreen.value,
|
||||||
(val: any) => {
|
(val) => {
|
||||||
options?.onFullscreen(val);
|
options?.onFullscreen(val);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@ -66,11 +66,9 @@ export declare function useForm(): {
|
|||||||
label?: string | undefined;
|
label?: string | undefined;
|
||||||
renderLabel?: any;
|
renderLabel?: any;
|
||||||
flex?: boolean | undefined;
|
flex?: boolean | undefined;
|
||||||
hidden?: boolean | ((options: {
|
hidden?: ((options: {
|
||||||
scope: obj;
|
scope: obj;
|
||||||
}) => boolean) | {
|
}) => boolean) | undefined;
|
||||||
value: boolean;
|
|
||||||
} | undefined;
|
|
||||||
prepend?: {
|
prepend?: {
|
||||||
[x: string]: any;
|
[x: string]: any;
|
||||||
name?: string | undefined;
|
name?: string | undefined;
|
||||||
@ -189,9 +187,9 @@ export declare function useForm(): {
|
|||||||
form: obj;
|
form: obj;
|
||||||
isReset?: boolean | undefined;
|
isReset?: boolean | undefined;
|
||||||
on?: {
|
on?: {
|
||||||
open?: ((data: obj) => void) | undefined;
|
open?: ((data: any) => void) | undefined;
|
||||||
close?: ((action: ClForm.CloseAction, done: fn) => void) | undefined;
|
close?: ((action: ClForm.CloseAction, done: fn) => void) | undefined;
|
||||||
submit?: ((data: obj, event: {
|
submit?: ((data: any, event: {
|
||||||
close: fn;
|
close: fn;
|
||||||
done: fn;
|
done: fn;
|
||||||
}) => void) | undefined;
|
}) => void) | undefined;
|
||||||
|
|||||||
@ -42,6 +42,9 @@ export declare function useTable(props: any): {
|
|||||||
search: {
|
search: {
|
||||||
isInput: boolean;
|
isInput: boolean;
|
||||||
value: any;
|
value: any;
|
||||||
|
refreshOnChange: {
|
||||||
|
valueOf: () => boolean;
|
||||||
|
};
|
||||||
component: {
|
component: {
|
||||||
[x: string]: any;
|
[x: string]: any;
|
||||||
name?: string | undefined;
|
name?: string | undefined;
|
||||||
|
|||||||
2
packages/crud/types/hooks/crud.d.ts
vendored
2
packages/crud/types/hooks/crud.d.ts
vendored
@ -1,7 +1,7 @@
|
|||||||
/// <reference types="../index" />
|
/// <reference types="../index" />
|
||||||
import { Ref } from "vue";
|
import { Ref } from "vue";
|
||||||
export declare function useCrud(options?: ClCrud.Options, cb?: (app: ClCrud.Ref) => void): Ref<ClCrud.Ref | undefined>;
|
export declare function useCrud(options?: ClCrud.Options, cb?: (app: ClCrud.Ref) => void): Ref<ClCrud.Ref | undefined>;
|
||||||
export declare function useUpsert<T = any>(options?: ClUpsert.Options<T>): Ref<ClUpsert.Ref<T> | undefined>;
|
export declare function useUpsert<T = any>(options?: ClUpsert.Options<T>): Ref<ClUpsert.Ref<any> | undefined>;
|
||||||
export declare function useTable<T = any>(options?: ClTable.Options<T>): Ref<ClTable.Ref<T> | undefined>;
|
export declare function useTable<T = any>(options?: ClTable.Options<T>): Ref<ClTable.Ref<T> | undefined>;
|
||||||
export declare function useForm<T = any>(cb?: (app: ClForm.Ref<T>) => void): Ref<ClForm.Ref<T> | undefined>;
|
export declare function useForm<T = any>(cb?: (app: ClForm.Ref<T>) => void): Ref<ClForm.Ref<T> | undefined>;
|
||||||
export declare function useAdvSearch<T = any>(options?: ClAdvSearch.Options<T>): Ref<ClAdvSearch.Ref<T> | undefined>;
|
export declare function useAdvSearch<T = any>(options?: ClAdvSearch.Options<T>): Ref<ClAdvSearch.Ref<T> | undefined>;
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
export const proxy = {
|
export const proxy = {
|
||||||
"/dev/": {
|
"/dev/": {
|
||||||
target: "https://test-admin.cool-js.cloud",
|
target: "http://127.0.0.1:8001",
|
||||||
// target: "http://127.0.0.1:8001",
|
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: (path: string) => path.replace(/^\/dev/, "")
|
rewrite: (path: string) => path.replace(/^\/dev/, "")
|
||||||
},
|
},
|
||||||
|
|||||||
@ -35,7 +35,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useCrud, useForm, useTable, useUpsert } from "@cool-vue/crud";
|
import { useCrud, useForm, useTable, useUpsert, setFocus } from "@cool-vue/crud";
|
||||||
import { useCool } from "/@/cool";
|
import { useCool } from "/@/cool";
|
||||||
|
|
||||||
const { refs, setRefs, service } = useCool();
|
const { refs, setRefs, service } = useCool();
|
||||||
@ -57,7 +57,8 @@ const Upsert = useUpsert({
|
|||||||
name: "el-date-picker"
|
name: "el-date-picker"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
plugins: [setFocus()]
|
||||||
});
|
});
|
||||||
|
|
||||||
// cl-table
|
// cl-table
|
||||||
@ -104,7 +105,7 @@ function open() {
|
|||||||
labelPosition: "top"
|
labelPosition: "top"
|
||||||
},
|
},
|
||||||
dialog: {
|
dialog: {
|
||||||
height: "500px",
|
height: "70vh",
|
||||||
width: "1000px"
|
width: "1000px"
|
||||||
},
|
},
|
||||||
items: [
|
items: [
|
||||||
|
|||||||
@ -151,7 +151,8 @@ function refresh(params?: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 新增、编辑
|
// 新增、编辑
|
||||||
const Upsert = useUpsert({
|
// 插入类型 <Eps.UserInfoEntity>,prop 和 data 会有提示
|
||||||
|
const Upsert = useUpsert<Eps.UserInfoEntity>({
|
||||||
dialog: {
|
dialog: {
|
||||||
height: "600px", // 固定高
|
height: "600px", // 固定高
|
||||||
width: "1000px" // 固定宽
|
width: "1000px" // 固定宽
|
||||||
@ -165,15 +166,15 @@ const Upsert = useUpsert({
|
|||||||
type: "card",
|
type: "card",
|
||||||
labels: [
|
labels: [
|
||||||
{
|
{
|
||||||
label: "基础",
|
label: "基础信息",
|
||||||
value: "base"
|
value: "base"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "选择",
|
label: "选择用户",
|
||||||
value: "select"
|
value: "select"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "其他",
|
label: "其他配置",
|
||||||
value: "other"
|
value: "other"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -181,7 +182,7 @@ const Upsert = useUpsert({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "头像",
|
label: "头像",
|
||||||
prop: "avatar",
|
prop: "avatarUrl",
|
||||||
group: "base",
|
group: "base",
|
||||||
component: {
|
component: {
|
||||||
name: "cl-upload"
|
name: "cl-upload"
|
||||||
@ -240,13 +241,34 @@ const Upsert = useUpsert({
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "省市区",
|
prop: "contact",
|
||||||
prop: "pca",
|
|
||||||
group: "base",
|
group: "base",
|
||||||
component: {
|
component: {
|
||||||
name: "cl-distpicker"
|
name: "cl-form-card",
|
||||||
}
|
props: {
|
||||||
|
label: "联系信息",
|
||||||
|
expand: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
label: "手机号",
|
||||||
|
prop: "phone",
|
||||||
|
component: {
|
||||||
|
name: "el-input"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "省市区",
|
||||||
|
prop: "pca",
|
||||||
|
group: "base",
|
||||||
|
component: {
|
||||||
|
name: "cl-distpicker"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
label: "",
|
label: "",
|
||||||
prop: "userIds",
|
prop: "userIds",
|
||||||
@ -400,7 +422,6 @@ const Table = useTable({
|
|||||||
|
|
||||||
// 带搜索组件
|
// 带搜索组件
|
||||||
search: {
|
search: {
|
||||||
// cool渲染方式
|
|
||||||
component: {
|
component: {
|
||||||
name: "el-input",
|
name: "el-input",
|
||||||
props: {
|
props: {
|
||||||
@ -430,7 +451,6 @@ const Table = useTable({
|
|||||||
|
|
||||||
// 带搜索组件
|
// 带搜索组件
|
||||||
search: {
|
search: {
|
||||||
// jsx方式
|
|
||||||
component: {
|
component: {
|
||||||
name: "cl-select",
|
name: "cl-select",
|
||||||
props: {
|
props: {
|
||||||
@ -455,9 +475,14 @@ const Table = useTable({
|
|||||||
prop: "createTime",
|
prop: "createTime",
|
||||||
sortable: "custom",
|
sortable: "custom",
|
||||||
search: {
|
search: {
|
||||||
component: (
|
component: {
|
||||||
<cl-date-picker type="date" value-format="YYYY-MM-DD" placeholder="搜索日期" />
|
name: "cl-date-picker",
|
||||||
)
|
props: {
|
||||||
|
type: "date",
|
||||||
|
valueFormat: "YYYY-MM-DD",
|
||||||
|
placeholder: "搜索日期"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -344,10 +344,10 @@
|
|||||||
"@babel/helper-validator-identifier" "^7.22.20"
|
"@babel/helper-validator-identifier" "^7.22.20"
|
||||||
to-fast-properties "^2.0.0"
|
to-fast-properties "^2.0.0"
|
||||||
|
|
||||||
"@cool-vue/crud@^7.1.0":
|
"@cool-vue/crud@^7.1.3":
|
||||||
version "7.1.0"
|
version "7.1.3"
|
||||||
resolved "https://registry.npmjs.org/@cool-vue/crud/-/crud-7.1.0.tgz#bed31f8059f55fba9dafa03b028216ac52685fe6"
|
resolved "https://registry.yarnpkg.com/@cool-vue/crud/-/crud-7.1.3.tgz#494823c9b9d3db7c03624ee82b5d59330977989e"
|
||||||
integrity sha512-ai3QIim55AuWGSpRqgYU4b7vppfqFx4V7vP1htDIwhdY9oMGRiyzedjE1yvwuvHE7E9By9zuMfO5D8AuB9lXbQ==
|
integrity sha512-jSCLPfD/ADfarhI/4e6dWLWmXh2LxTGED4W1RwhgNZWFbM7zSjTc4bPfK3v8AMEcELs6e2ZIFGfcurlG/qc8AQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
array.prototype.flat "^1.2.4"
|
array.prototype.flat "^1.2.4"
|
||||||
core-js "^3.21.1"
|
core-js "^3.21.1"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user