Skip to content

Commit

Permalink
feat: 将ui-interface单独抽出来
Browse files Browse the repository at this point in the history
  • Loading branch information
greper committed Jun 14, 2021
1 parent b50b877 commit 6bcc22a
Show file tree
Hide file tree
Showing 27 changed files with 503 additions and 47 deletions.
5 changes: 5 additions & 0 deletions packages/demo-antdv/src/router/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const resources = [
title: "国际化",
path: "/basis/i18n",
component: "/basis/i18n/index.vue"
},
{
title: "debug",
path: "/debug/select",
component: "/debug/select/index.vue"
}
]
},
Expand Down
42 changes: 42 additions & 0 deletions packages/demo-antdv/src/views/debug/select/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { requestForMock } from "/src/api/service";
const request = requestForMock;
const apiPrefix = "/DebugSelect";
export function GetList(query) {
return request({
url: apiPrefix + "/page",
method: "get",
data: query
});
}

export function AddObj(obj) {
return request({
url: apiPrefix + "/add",
method: "post",
data: obj
});
}

export function UpdateObj(obj) {
return request({
url: apiPrefix + "/update",
method: "post",
data: obj
});
}

export function DelObj(id) {
return request({
url: apiPrefix + "/delete",
method: "post",
params: { id }
});
}

export function GetObj(id) {
return request({
url: apiPrefix + "/info",
method: "get",
params: { id }
});
}
64 changes: 64 additions & 0 deletions packages/demo-antdv/src/views/debug/select/crud.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import * as api from "./api";
import { requestForMock } from "/src/api/service";
import { dict } from "@fast-crud/fast-crud";
export default function ({ expose }) {
const pageRequest = async (query) => {
return await api.GetList(query);
};
const editRequest = async ({ form, row }) => {
form.id = row.id;
return await api.UpdateObj(form);
};
const delRequest = async ({ row }) => {
return await api.DelObj(row.id);
};

const addRequest = async ({ form }) => {
return await api.AddObj(form);
};
let dict1 = dict({
url: "/dicts/OpenStatusEnum?simple"
});
dict1.loadDict();
return {
crudOptions: {
request: {
pageRequest,
addRequest,
editRequest,
delRequest
},
form: {
// 单列布局
col: { span: 24 },
labelCol: { span: 4 },
wrapperCol: { span: 18 }
},
columns: {
id: {
title: "ID",
key: "id",
type: "number",
column: {
width: 50
},
form: {
show: false
}
},

statusRemote: {
title: "单选远程",
search: {
show: true
},
type: "dict-select",
dict: dict1,
form: {
rules: [{ required: true, message: "请选择一个选项" }]
}
}
}
}
};
}
38 changes: 38 additions & 0 deletions packages/demo-antdv/src/views/debug/select/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<template>
<fs-crud ref="crudRef" v-bind="crudBinding" />
</template>

<script>
import { defineComponent, ref, onMounted } from "vue";
import { useCrud } from "@fast-crud/fast-crud";
import createCrudOptions from "./crud";
import { useExpose } from "@fast-crud/fast-crud";
export default defineComponent({
name: "DebugSelect",
setup() {
// crud组件的ref
const crudRef = ref();
// crud 配置的ref
const crudBinding = ref();
// 暴露的方法
const { expose } = useExpose({ crudRef, crudBinding });
// 你的crud配置
const { crudOptions } = createCrudOptions({ expose });
// 初始化crud配置
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars
const { resetCrudOptions } = useCrud({ expose, crudOptions });
// 你可以调用此方法,重新初始化crud配置
// resetCrudOptions(options)
// 页面打开后获取列表数据
onMounted(() => {
expose.doRefresh();
});
return {
crudBinding,
crudRef
};
}
});
</script>
9 changes: 9 additions & 0 deletions packages/demo-antdv/src/views/debug/select/mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import mockUtil from "/src/mock/base";
const options = {
name: "DebugSelect",
idGenerator: 0
};
const list = [];
options.list = list;
const mock = mockUtil.buildMock(options);
export default mock;
3 changes: 2 additions & 1 deletion packages/demo-antdv/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export default ({ command, mode }) => {
{ find: /@fast-crud\/fast-crud$/, replacement: path.resolve("../fast-crud/src/") },
{ find: /@fast-crud\/extends-uploader\/dist/, replacement: path.resolve("../extends/extends-uploader/src/") },
{ find: /@fast-crud\/extends-uploader$/, replacement: path.resolve("../extends/extends-uploader/src/") },
{ find: /@fast-crud\/ui-antdv$/, replacement: path.resolve("../ui/ui-antdv/src/") }
{ find: /@fast-crud\/ui-antdv$/, replacement: path.resolve("../ui/ui-antdv/src/") },
{ find: /@fast-crud\/ui-interface$/, replacement: path.resolve("../ui/ui-interface/src/") }
];
}

Expand Down
26 changes: 13 additions & 13 deletions packages/demo-antdv/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,10 @@
minimatch "^3.0.4"
strip-json-comments "^3.1.1"

"@fast-crud/extends-uploader@^0.9.0":
version "0.9.0"
resolved "https://registry.yarnpkg.com/@fast-crud/extends-uploader/-/extends-uploader-0.9.0.tgz#acf7a58dd62dc4f1a6ee4ab983f5a5725853eaf6"
integrity sha512-7yGDA9ZWTYbwo+1kaGUD8tiFrzaOzfG2nHx+vCe/5K20Pn1b1OAQDwFmbBkqNbpY9kQGyCmGHKIjKDcxxeB6yw==
"@fast-crud/extends-uploader@^0.9.3":
version "0.9.3"
resolved "https://registry.npmjs.org/@fast-crud/extends-uploader/-/extends-uploader-0.9.3.tgz#77c268a33e55abbd21de4a66847f8ab9e11f8972"
integrity sha512-dhdT2WL6om9pmzatP3CspMin4T6rlOTSIwfF2uculQWyUedhcq2c2SFsutaQ+3M44+NYxo847jNnohibzXtoYw==
dependencies:
ali-oss "^6.13.2"
cos-js-sdk-v5 "^1.2.9"
Expand All @@ -341,10 +341,10 @@
vue "^3.0.7"
vue-cropperjs "^5.0.0"

"@fast-crud/fast-crud@^0.9.0":
version "0.9.0"
resolved "https://registry.yarnpkg.com/@fast-crud/fast-crud/-/fast-crud-0.9.0.tgz#852770de00b4e90661bbc86fcbaa442edbb738dc"
integrity sha512-eXV3mBaeA35J3ciMiODGJ0lj0W4qlIGjIxb5KgcklGa8gDw5jZc1s+4Zb7NgH604FcoZaPPzgNtFiYSrJTkcaQ==
"@fast-crud/fast-crud@^0.9.3":
version "0.9.3"
resolved "https://registry.npmjs.org/@fast-crud/fast-crud/-/fast-crud-0.9.3.tgz#3f924115264a5d72596269187c583dfb78c5f13d"
integrity sha512-PWwwb2mTbH7UYRrncH72MnRrNFqS5RH2iPIQSlMIdU8ailsJsnghPbKCZ+t4ydqHz+pDl5NrALDFEyjRxpR9mQ==
dependencies:
dayjs "^1.10.4"
deepdash-es "5.3.5"
Expand All @@ -353,13 +353,13 @@
vue "^3.0.7"
vuedraggable "^4.0.1"

"@fast-crud/ui-antdv@^0.9.0":
version "0.9.0"
resolved "https://registry.yarnpkg.com/@fast-crud/ui-antdv/-/ui-antdv-0.9.0.tgz#eeae0794a26ff494bef9435daca28b33171b0694"
integrity sha512-5GwcW5HmcDCUabaArArBBDmnLt0db2VATKNYtRYfkyGSsJSQb375BW+Ei2fhpITaDir/UjB9+oRRCnmfRMB6AA==
"@fast-crud/ui-antdv@^0.9.3":
version "0.9.3"
resolved "https://registry.npmjs.org/@fast-crud/ui-antdv/-/ui-antdv-0.9.3.tgz#ba99948fad24a591928972c971f54dc19ab0fc6d"
integrity sha512-jQYjAavFIQNaXX8WLerdCFLY9klUUL+IEUpINtaFIlCOq8S5VfnnPZSRnkRhJxqb1hdwdCz15o/7fKnB7OdAwA==
dependencies:
"@ant-design/icons-vue" "^6.0.1"
"@fast-crud/fast-crud" "^0.9.0"
"@fast-crud/fast-crud" "^0.9.3"
ant-design-vue "^2.1.4"
vue "^3.0.7"

Expand Down
3 changes: 2 additions & 1 deletion packages/demo-element/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default ({ command, mode }) => {
{ find: /@fast-crud\/fast-crud$/, replacement: path.resolve("../fast-crud/src/") },
{ find: /@fast-crud\/extends-uploader\/dist/, replacement: path.resolve("../extends/extends-uploader/src/") },
{ find: /@fast-crud\/extends-uploader$/, replacement: path.resolve("../extends/extends-uploader/src/") },
{ find: /@fast-crud\/ui-element$/, replacement: path.resolve("../ui/ui-element/src/") }
{ find: /@fast-crud\/ui-element$/, replacement: path.resolve("../ui/ui-element/src/") },
{ find: /@fast-crud\/ui-interface$/, replacement: path.resolve("../ui/ui-interface/src/") }
];
}

Expand Down
3 changes: 2 additions & 1 deletion packages/fast-crud/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"lodash-es": "^4.17.15",
"lru-cache": "^6.0.0",
"vue": "^3.0.7",
"vuedraggable": "^4.0.1"
"vuedraggable": "^4.0.1",
"@fast-crud/ui-interface": "^0.9.3"
},
"devDependencies": {
"@commitlint/cli": "^12.0.1",
Expand Down
4 changes: 3 additions & 1 deletion packages/fast-crud/src/components/extends/fs-dict-select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import { computed } from "vue";
import { useDict } from "../../use/use-dict";
import { useI18n } from "../../locale";
import { useUi } from "../../use";
/**
* 字典选择框
Expand Down Expand Up @@ -41,9 +42,10 @@ export default {
return props.placeholder || t("fs.component.select.placeholder");
});
const { ui } = useUi();
return {
computedPlaceholder,
...useDict(props, ctx)
...useDict(props, ctx, ui.select.modelValue)
};
}
};
Expand Down
32 changes: 27 additions & 5 deletions packages/fast-crud/src/components/search/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
ref="searchFormRef"
:model="form"
v-bind="options"
:rules="computedRules"
class="fs-search-form"
@compositionstart="changeInputEventDisabled(true)"
@compositionend="changeInputEventDisabled(false)"
Expand Down Expand Up @@ -60,7 +61,7 @@
</template>

<script>
import { computed, ref, reactive, nextTick } from "vue";
import { computed, nextTick, reactive, ref } from "vue";
import _ from "lodash-es";
import fsButton from "../basic/fs-button";
import FsComponentRender from "../../components/render/fs-component-render";
Expand Down Expand Up @@ -141,6 +142,12 @@ export default {
show: {
type: Boolean,
default: true
},
/**
* 是否启用校验
*/
validate: {
default: false
}
},
emits: [
Expand Down Expand Up @@ -242,7 +249,15 @@ export default {
return btns;
});
const computedColumns = doComputed(props.columns, getContextFn);
const computedColumns = doComputed(props.columns, getContextFn, null, (value) => {
if (!props.validate) {
//去掉rules
_.forEach(value, (item) => {
delete item.rules;
});
}
return value;
});
function initAutoSearch() {
// 构建防抖查询函数
Expand Down Expand Up @@ -306,10 +321,16 @@ export default {
doAutoSearch();
}
const computedRules = computed(() => {
if (!props.validate) {
return [];
}
return props.options.rules;
});
return {
get: (form, key) => {
const ret = _.get(form, key);
return ret;
return _.get(form, key);
},
onValueChanged,
doSearch,
Expand All @@ -325,7 +346,8 @@ export default {
inputEventDisabled,
changeInputEventDisabled,
computedColumns,
computedButtons
computedButtons,
computedRules
};
}
};
Expand Down
3 changes: 1 addition & 2 deletions packages/fast-crud/src/ui/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { UiInterface } from "./ui-interface";
export * from "./ui-interface";
import { UiInterface } from "@fast-crud/ui-interface";
import { reactive } from "vue";
import _ from "lodash-es";
export class UiContext {
Expand Down
9 changes: 3 additions & 6 deletions packages/fast-crud/src/use/use-dict-define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Dict extends UnMergeable {
children = "children";
color = "color";
isTree = false;
data: undefined | Array<any> = undefined;
data: null | Array<any> = null;
originalData: undefined | Array<any> = undefined;
dataMap = {};
loading = false;
Expand All @@ -61,9 +61,6 @@ class Dict extends UnMergeable {
this.originalData = dict.data;
this.setData(dict.data);
}
if (!this.prototype && this.immediate) {
this.loadDict();
}
}

isDynamic() {
Expand Down Expand Up @@ -147,7 +144,7 @@ class Dict extends UnMergeable {
}

clear() {
this.data = undefined;
this.data = null;
this.dataMap = {};
}

Expand Down Expand Up @@ -283,7 +280,7 @@ class Dict extends UnMergeable {

function dict(config) {
const ret = reactive(new Dict(config));
if (ret.immediate && !ret.prototype) {
if (!ret.prototype && ret.immediate) {
ret.loadDict();
}
return ret;
Expand Down
Loading

0 comments on commit 6bcc22a

Please sign in to comment.