@xuekl/cli-components 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/XklDict.vue ADDED
@@ -0,0 +1,15 @@
1
+ <template>
2
+ <el-select style="width: 100%;">
3
+ <el-option v-for="item in list" :key="item.id" :label="item.dicValue" :value="item.dicKey"></el-option>
4
+ </el-select>
5
+ </template>
6
+ <script setup lang="ts">
7
+ import storeController from '@/controller/common/store.controller';
8
+ import { defineProps, reactive } from 'vue'
9
+ const props = defineProps(['dict'])
10
+ const { dict } = reactive(props)
11
+ const { dictList } = storeController
12
+
13
+ const list = dictList.filter(res => res.type === dict)
14
+ console.log(list)
15
+ </script>
package/XklForm.vue ADDED
@@ -0,0 +1,133 @@
1
+ <template>
2
+ <el-form ref="xklForm" :model="form" :label-width="config.labelWidth">
3
+ <el-row :gutter="20">
4
+ <template v-for="item in formList" :key="item.key">
5
+ <el-col v-if="item.show()" :span="item.span || config.span">
6
+ <el-form-item :label="item.label" :label-width="item.labelWidth" :rules="item.rules" :prop="item.key">
7
+ <slot v-if="item.slot" :name="item.key"></slot>
8
+ <div v-else style="width: 100%;display: flex;">
9
+ <XklDict v-if="item.dict" v-model="form[item.key]" clearable :placeholder="item.placeholder"
10
+ :dict="item.dict" :disabled="item.disabled()"></XklDict>
11
+ <XklSelect v-else-if="item.url || item.list" v-model="form[item.key]"
12
+ :placeholder="item.placeholder" :config="item" clearable :disabled="item.disabled()">
13
+ </XklSelect>
14
+ <el-checkbox-group v-else-if="item.boxes" v-model="form[item.key]">
15
+ <el-checkbox v-for="box in item.boxes" :label="box.value" :key="box.value">{{ box.label
16
+ }}</el-checkbox>
17
+ </el-checkbox-group>
18
+ <el-radio-group v-else-if="item.radios" v-model="form[item.key]">
19
+ <el-radio v-for="rad in item.radios" :label="rad.value" :key="rad.value">{{ rad.label
20
+ }}</el-radio>
21
+ </el-radio-group>
22
+ <el-input type="textarea" v-else-if="item.rows" v-model="form[item.key]"
23
+ :placeholder="item.placeholder" :disabled="item.disabled()" :rows="item.rows"
24
+ :autosize="item.autosize" :maxlength="item.maxlength" :minlength="item.minlength"
25
+ :show-word-limit="item.showWordLimit"></el-input>
26
+ <el-input v-else v-model="form[item.key]" :placeholder="item.placeholder"
27
+ :disabled="item.disabled()" :maxlength="item.maxlength" :minlength="item.minlength"
28
+ :show-word-limit="item.showWordLimit"></el-input>
29
+ </div>
30
+ </el-form-item>
31
+ </el-col>
32
+ </template>
33
+ <el-col :span="config.span">
34
+ <slot name="_action"></slot>
35
+ </el-col>
36
+ </el-row>
37
+ </el-form>
38
+ </template>
39
+
40
+ <script setup lang="ts">
41
+ import { Ref, defineProps, onMounted, reactive, ref, watch } from 'vue'
42
+ import { setUpperFirst } from '@/utils'
43
+ import XklSelect from './XklSelect.vue';
44
+ import XklDict from './XklDict.vue'
45
+ import { RuleItem } from 'async-validator';
46
+
47
+ const props = defineProps(['form'])
48
+ const { form } = reactive(props)
49
+
50
+ const formList: Ref = ref([])
51
+
52
+ const config = form.getConfig()
53
+ const options = form.getOptions()
54
+ const xklForm: Ref = ref(null)
55
+
56
+ Object.keys(form).forEach(key => {
57
+ const upperKey = setUpperFirst(key)
58
+ if (form['get' + upperKey]) {
59
+ const item = form['get' + upperKey]()
60
+
61
+ const placelabel = item.label.replace(':', '').replace(':', '').trim()
62
+ if (item.dict || item.url || item.list) {
63
+ item.placeholder = item.placeholder || '请选择' + placelabel
64
+ } else {
65
+ item.placeholder = item.placeholder || '请输入' + placelabel
66
+ }
67
+
68
+ item.required = item.required || (() => false)
69
+ item.show = item.show || (() => true)
70
+ item.disabled = item.disabled || (() => false)
71
+
72
+ if (options.mode === 'search') {
73
+ item.rules = ref([])
74
+ if (item.mode === 'search') {
75
+ formList.value.push({
76
+ key: key,
77
+ ...item
78
+ })
79
+ }
80
+ } else {
81
+ if (item.rules) {
82
+ item.rules = ref(item.rules)
83
+ } else {
84
+ item.rules = ref([])
85
+ }
86
+
87
+ if (item.required()) {
88
+ item.rules.value.push({ required: true, message: '请输入' + placelabel, trigger: 'blur' })
89
+ }
90
+
91
+ watch(item.required, (newVal) => {
92
+ if (newVal) {
93
+ item.rules.value.push({ required: true, message: '请输入' + placelabel, trigger: 'blur' })
94
+ } else {
95
+ item.rules.value = item.rules.value.filter((item: RuleItem) => !item.required)
96
+ xklForm.value.clearValidate([key])
97
+ }
98
+ })
99
+ formList.value.push({
100
+ key: key,
101
+ ...item
102
+ })
103
+ }
104
+
105
+ }
106
+
107
+ const regProto = () => {
108
+ let enableSubmit = true
109
+ form.setSubmit((call: (fn: () => void) => void) => {
110
+ if (enableSubmit) {
111
+ enableSubmit = false
112
+ xklForm.value.validate((valid: boolean) => {
113
+ if (valid) {
114
+ call(() => {
115
+ setTimeout(() => {
116
+ enableSubmit = true
117
+ }, 300)
118
+ })
119
+ } else {
120
+ enableSubmit = true
121
+ }
122
+ })
123
+ }
124
+ })
125
+ form.setResetFields(xklForm.value.resetFields)
126
+ }
127
+
128
+ onMounted(() => {
129
+ regProto()
130
+ })
131
+ })
132
+
133
+ </script>
package/XklSelect.vue ADDED
@@ -0,0 +1,28 @@
1
+ <template>
2
+ <el-select style="width: 100%;">
3
+ <el-option v-for="item in dataList" :key="item.key" :label="item[config.labelTarget] || item.label"
4
+ :value="item[config.valueTarget] || item.value"></el-option>
5
+ </el-select>
6
+ </template>
7
+ <script setup lang="ts">
8
+ import { Ref, defineProps, reactive, ref } from 'vue';
9
+ import http from '@/utils/httpRequest'
10
+ const props = defineProps(['config'])
11
+
12
+ const { config } = reactive(props)
13
+
14
+ const dataList: Ref = ref([])
15
+
16
+ if (config.list) {
17
+ dataList.value = config.list
18
+ } else if (config.url) {
19
+ http({
20
+ url: http.adornUrl(config.url),
21
+ method: 'get',
22
+ params: http.adornParams({})
23
+ }).then(({ data }) => {
24
+ dataList.value = data.data
25
+ })
26
+ }
27
+
28
+ </script>
package/XklTable.vue ADDED
@@ -0,0 +1,25 @@
1
+ <template>
2
+ <el-table :data="table.list" style="width: 100%">
3
+ <el-table-column v-if="table.selection" type="selection"></el-table-column>
4
+ <el-table-column v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label"
5
+ :width="item.width"></el-table-column>
6
+ <el-table-column fixed="right" :label="operation.label">
7
+ <template #default="{ row }">
8
+ <slot name="_operation" :row="row"></slot>
9
+ </template>
10
+ </el-table-column>
11
+ <template #empty>
12
+ <el-empty description="暂无数据"></el-empty>
13
+ </template>
14
+ </el-table>
15
+ </template>
16
+ <script setup lang="ts">
17
+ import { TableColumn, TableOperation } from '@xuekl/cli-base/types';
18
+ import { defineProps, reactive } from 'vue'
19
+ const props = defineProps(['table'])
20
+ const { table } = reactive(props)
21
+
22
+ const columns: TableColumn[] = table.columns
23
+ const operation: TableOperation = table.operation
24
+
25
+ </script>
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@xuekl/cli-components",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "publishConfig": {
13
+ "access": "public"
14
+ }
15
+ }