general-basic-form 2.0.2 → 2.0.4

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.
@@ -1,234 +0,0 @@
1
- <!--
2
- * @Author: 陈德立*******419287484@qq.com
3
- * @Date: 2021-08-20 17:14:53
4
- * @LastEditTime: 2023-11-14 15:18:20
5
- * @LastEditors: 陈德立*******419287484@qq.com
6
- * @Github: https://github.com/Alan1034
7
- * @Description:
8
- * @FilePath: \GeneralBasicForm\src\GeneralBasicForm.vue
9
- *
10
- -->
11
- /** 通用基本表单。用在表单页面搜索栏 */
12
-
13
- <template>
14
- <el-form
15
- :model="queryParams"
16
- ref="queryFormRef"
17
- v-show="showSearch"
18
- inline
19
- label-position="left"
20
- :label-width="labelWidth"
21
- v-bind="$attrs"
22
- >
23
- <el-form-item
24
- v-for="item in formItem"
25
- :label="item.label"
26
- :prop="item.prop"
27
- :key="item.prop"
28
- :rules="item.rules"
29
- >
30
- <Input v-if="item.type === 'input'" :item="item" />
31
- <InputGraphicVerification
32
- v-if="item.type === 'input-graphic-verification'"
33
- :item="item"
34
- :key="item.key"
35
- />
36
- <InputMobileVerification
37
- v-if="item.type === 'input-mobile-verification'"
38
- :item="item"
39
- />
40
- <Divider v-if="item.type === 'divider'" :item="item" />
41
- <el-select
42
- filterable
43
- v-else-if="item.type === 'select'"
44
- v-model="queryParams[item.prop]"
45
- :size="size"
46
- v-bind="item.selectSetting || selectSetting"
47
- >
48
- <el-option
49
- v-for="dict in item.option || []"
50
- :key="dict.value"
51
- :label="dict.desc"
52
- :value="dict.value"
53
- />
54
- </el-select>
55
- <el-cascader
56
- filterable
57
- v-else-if="item.type === 'cascader'"
58
- v-model="queryParams[item.prop]"
59
- :size="size"
60
- :options="item.options || []"
61
- v-bind="item.selectSetting || selectSetting"
62
- ></el-cascader>
63
- <el-date-picker
64
- v-else-if="item.type === 'date-picker'"
65
- v-model="queryParams[item.prop]"
66
- :size="size"
67
- v-bind="item.datePackerSetting || datePackerSetting"
68
- ></el-date-picker>
69
- <InputNumber v-if="item.type === 'input-number'" :item="item" />
70
- </el-form-item>
71
- <slot></slot>
72
- <el-form-item v-if="!formOnly">
73
- <el-button
74
- type="primary"
75
- icon="el-icon-search"
76
- :size="size"
77
- @click="handleQuery"
78
- >查询</el-button
79
- >
80
- <el-button icon="el-icon-refresh" :size="size" @click="resetQuery"
81
- >重置</el-button
82
- >
83
- </el-form-item>
84
- </el-form>
85
- </template>
86
-
87
- <script lang="ts">
88
- import { provide, ref, PropType, defineComponent } from "vue";
89
- import type { ItemType } from "./types/basicFrom";
90
- import { useRoute } from "vue-router";
91
- import Input from "./components/VBasic/input";
92
- import InputNumber from "./components/VBasic/input-number";
93
- import InputGraphicVerification from "./components/VBasic/input-graphic-verification";
94
- import InputMobileVerification from "./components/VBasic/input-mobile-verification";
95
- import Divider from "./components/VBasic/divider";
96
-
97
- export default defineComponent({
98
- name: "GeneralBasicForm",
99
- components: {
100
- Input,
101
- InputNumber,
102
- InputGraphicVerification,
103
- InputMobileVerification,
104
- Divider,
105
- },
106
- props: {
107
- showSearch: {
108
- // 是否展示所有元素
109
- type: Boolean,
110
- default: true,
111
- },
112
- formOnly: {
113
- // 是否只展示表单不展示按钮
114
- type: Boolean,
115
- default: false,
116
- },
117
- getList: {
118
- // 查找数据调用的函数
119
- type: Function,
120
- default: () => {},
121
- },
122
- afterReset: {
123
- // 在重置按钮点击完后但还没重新请求时触发的的函数
124
- type: Function,
125
- default: () => {},
126
- },
127
- formItem: {
128
- // 定义表单的数据
129
- type: Array as unknown as PropType<ItemType[]>,
130
- default: [],
131
- },
132
- size: {
133
- // 控制按钮大小
134
- type: String,
135
- default: "medium",
136
- },
137
- labelWidth: {
138
- // 表单文字宽度
139
- type: String,
140
- default: "90px",
141
- },
142
- noUrlParameters: {
143
- // 不接受和不改变url的参数
144
- type: Boolean,
145
- default: () => false,
146
- },
147
- formData: {
148
- // 外部传入的表单数据,用于回填
149
- type: Object,
150
- default: () => {},
151
- },
152
- },
153
- data() {
154
- return {
155
- selectSetting: {
156
- placeholder: "请选择",
157
- clearable: true,
158
- style: "width: 200px",
159
- },
160
- datePackerSetting: {
161
- style: "width: 227px",
162
- "start-placeholder": "开始日期",
163
- "end-placeholder": "结束日期",
164
- type: "daterange",
165
- },
166
- };
167
- },
168
- setup(props) {
169
- const { size, noUrlParameters, getList } = props;
170
- const route = useRoute();
171
- const queryParams = ref({
172
- ...(noUrlParameters ? {} : route?.query),
173
- }); // form表单数据
174
- provide(/* 注入名 */ "queryParams", /* 值 */ queryParams);
175
- provide(/* 注入名 */ "size", /* 值 */ size);
176
- provide(/* 注入名 */ "getList", /* 值 */ getList);
177
- // const { formItem } = toRefs(props);
178
- // const { formItem } = props;
179
- // console.log(formItem);
180
- // const queryParams = {};
181
- // formItem.forEach((item) => {
182
- // queryParams[item.prop] = "";
183
- // });
184
- return {
185
- queryParams,
186
- };
187
- },
188
- watch: {
189
- formData(val) {
190
- this.queryParams = {
191
- ...(this.noUrlParameters ? {} : this.queryParams),
192
- ...val,
193
- };
194
- },
195
- },
196
- methods: {
197
- /** 搜索按钮操作 */
198
- handleQuery() {
199
- const params = { page: 1, limit: 10 };
200
- const searchParams = {
201
- ...this.$route?.query,
202
- ...this.queryParams,
203
- ...params,
204
- };
205
- if (!this.noUrlParameters) {
206
- this.$router.push({
207
- query: { ...searchParams },
208
- });
209
- }
210
- this.getList({
211
- ...searchParams,
212
- });
213
- },
214
- /** 重置按钮操作 */
215
- async resetQuery() {
216
- this.$refs.queryFormRef.resetFields();
217
- const params = { page: 1 };
218
- if (!this.noUrlParameters) {
219
- await this.$router.push({
220
- query: { ...params },
221
- });
222
- }
223
- this.queryParams = {
224
- ...(this.noUrlParameters ? {} : this.$route?.query),
225
- };
226
- this.afterReset();
227
- this.handleQuery();
228
- },
229
- },
230
- });
231
- </script>
232
-
233
- <style scoped>
234
- </style>
Binary file
@@ -1,52 +0,0 @@
1
- <!--
2
- * @Author: 陈德立*******419287484@qq.com
3
- * @Date: 2023-11-09 10:01:20
4
- * @LastEditTime: 2023-11-10 16:51:18
5
- * @LastEditors: 陈德立*******419287484@qq.com
6
- * @Github: https://github.com/Alan1034
7
- * @Description: 分割线
8
- * @FilePath: \deal-front-endd:\work\GeneralBasicForm\src\components\VBasic\divider\index.vue
9
- *
10
- -->
11
-
12
- <template>
13
- <el-divider v-bind="dividerSetting">
14
- <template v-for="(templateEle, name) in item.template" #[name]>
15
- <component
16
- :key="name"
17
- v-if="templateEle"
18
- :is="currentInputComponent()"
19
- :templateEle="templateEle"
20
- />
21
- </template>
22
- </el-divider>
23
- </template>
24
-
25
- <script lang="ts">
26
- import { defineComponent } from "vue";
27
-
28
- export default defineComponent({
29
- components: {
30
- slotArchive: (props) => {
31
- const { templateEle } = props;
32
- return templateEle();
33
- },
34
- },
35
- props: {
36
- item: null, // null就是any
37
- },
38
- setup() {},
39
- data() {
40
- return {
41
- dividerSetting: {
42
- ...this.item.dividerSetting,
43
- },
44
- };
45
- },
46
- methods: {
47
- currentInputComponent() {
48
- return "slot-archive";
49
- },
50
- },
51
- });
52
- </script>
@@ -1,67 +0,0 @@
1
- <template>
2
- <el-input
3
- @keydown.enter="getList"
4
- v-model="queryParams[item.prop]"
5
- :size="size"
6
- v-bind="inputSetting"
7
- >
8
- <template v-for="(templateEle, name) in item.template" #[name]>
9
- <component
10
- :key="name"
11
- v-if="templateEle"
12
- :is="currentInputComponent()"
13
- :templateEle="templateEle"
14
- />
15
- </template>
16
- </el-input>
17
- </template>
18
-
19
- <script lang="ts">
20
- import { defineComponent, inject } from "vue";
21
- import { inputDefaultSetting } from "../../setting";
22
- export default defineComponent({
23
- components: {
24
- InputArchive: (props) => {
25
- const { templateEle } = props;
26
- return templateEle();
27
- },
28
- },
29
- props: {
30
- item: null, // null就是any
31
- },
32
- setup() {
33
- const queryParams = inject("queryParams", {});
34
- const getList = inject("getList");
35
- const size = inject("size");
36
- return { queryParams, getList, size };
37
- },
38
- data() {
39
- return {
40
- inputSetting: {
41
- ...inputDefaultSetting,
42
- ...this.item.inputSetting,
43
- },
44
- };
45
- },
46
- // created() {
47
- // console.log("new", this.item);
48
- // console.log("new", this.inputSetting);
49
- // },
50
- methods: {
51
- currentInputComponent() {
52
- return "input-archive";
53
- },
54
- },
55
- // watch: {
56
- // item(val) {
57
- // console.log("item", val);
58
- // },
59
- // size(val) {
60
- // console.log(val);
61
- // },
62
- // },
63
- });
64
- </script>
65
-
66
- <style>
67
- </style>
@@ -1,56 +0,0 @@
1
- <!--
2
- * @Author: 陈德立*******419287484@qq.com
3
- * @Date: 2023-11-09 10:01:20
4
- * @LastEditTime: 2023-11-15 10:15:28
5
- * @LastEditors: 陈德立*******419287484@qq.com
6
- * @Github: https://github.com/Alan1034
7
- * @Description: 图形验证码组件
8
- * @FilePath: \GeneralBasicForm\src\components\VBasic\input-graphic-verification\index.vue
9
- *
10
- -->
11
-
12
- <script setup lang="ts">
13
- import Input from "../input/index.vue";
14
- import { ref, computed, PropType, toRefs } from "vue";
15
- import type {
16
- BasicFormComponentsProps,
17
- InputGraphicVerification,
18
- } from "../../../types/componentsProps";
19
- const { item } = defineProps<{ item: any }>();
20
- const { graphicSrc = "", getGraphic = () => {} }: InputGraphicVerification =
21
- item;
22
- const loading = ref(false);
23
-
24
- const graphicClick = async () => {
25
- // console.log('click', getGraphic);
26
- if (getGraphic && !loading.value) {
27
- loading.value = true;
28
- await getGraphic();
29
- loading.value = false;
30
- }
31
- };
32
- </script>
33
-
34
- <template>
35
- <div class="input-graphic-verification" v-loading="loading">
36
- <Input :item="item" class="input" />
37
- <img class="graphic" @click="graphicClick" :src="graphicSrc" />
38
- </div>
39
- </template>
40
-
41
- <style lang="less" scoped>
42
- .input-graphic-verification {
43
- display: flex;
44
- gap: 12px;
45
- width: 100%;
46
- .input {
47
- flex: auto;
48
- }
49
- .graphic {
50
- width: 109px;
51
- height: 43px;
52
- object-fit: fill;
53
- flex: none;
54
- }
55
- }
56
- </style>
@@ -1,31 +0,0 @@
1
- <!--
2
- * @Author: 陈德立*******419287484@qq.com
3
- * @Date: 2023-11-09 10:01:20
4
- * @LastEditTime: 2023-11-14 15:35:16
5
- * @LastEditors: 陈德立*******419287484@qq.com
6
- * @Github: https://github.com/Alan1034
7
- * @Description: 手机验证码组件
8
- * @FilePath: \GeneralBasicForm\src\components\VBasic\input-mobile-verification\index.vue
9
- *
10
- -->
11
-
12
- <script setup lang="ts">
13
- import Input from "../input/index.vue";
14
- import { h, watch, onBeforeUpdate, nextTick } from "vue";
15
- import { BasicFormComponentsProps } from "../../../types/componentsProps";
16
- import VerificationButton from "./verification-button.vue";
17
- const { item } = defineProps<{item:any}>();
18
- // 重新赋值一下触发下面的代码,否则响应会在内部进行
19
- const mobileItem = item;
20
- mobileItem.template = {
21
- append: () => {
22
- return h(VerificationButton, {
23
- getSmscode: mobileItem.getSmscode,
24
- });
25
- },
26
- };
27
- </script>
28
-
29
- <template>
30
- <Input :item="mobileItem" class="input"> </Input>
31
- </template>
@@ -1,64 +0,0 @@
1
- <script setup lang="ts">
2
- import { ref, computed, onBeforeUnmount, Ref } from "vue";
3
- import type { InputMobileVerification } from "../../../types/componentsProps";
4
- const { getSmscode } = defineProps<{ getSmscode: Function }>();
5
-
6
- const defaultText = "获取验证码";
7
- const restTime = 60;
8
- const buttonText: Ref<string | number> = ref(defaultText);
9
- const timer = ref(null);
10
- const buttonType = computed(() => buttonText.value === defaultText);
11
- const reset = () => {
12
- if (!timer) {
13
- return;
14
- }
15
- clearInterval(timer.value);
16
- timer.value = null;
17
- buttonText.value = defaultText;
18
- };
19
- const buttonClick = async () => {
20
- if (buttonText.value !== defaultText) {
21
- return;
22
- }
23
- buttonText.value = restTime;
24
- timer.value = setInterval(() => {
25
- if (Number(buttonText.value) <= 0 || !buttonText.value) {
26
- reset();
27
- return;
28
- } else {
29
- buttonText.value = Number(buttonText.value) - 1;
30
- }
31
- }, 1000);
32
- if (!getSmscode) {
33
- return;
34
- } else {
35
- const statue = await getSmscode();
36
- if (statue === false) {
37
- reset();
38
- }
39
- }
40
- };
41
- onBeforeUnmount(() => {
42
- reset();
43
- });
44
- </script>
45
-
46
- <template>
47
- <el-button
48
- class="verifiaction-button"
49
- :style="{
50
- color: buttonType
51
- ? 'var(--color-primary, #409EFF)'
52
- : 'var(--text-color-placeholder, #A8ABB2)',
53
- cursor: buttonType ? 'pointer' : 'default',
54
- }"
55
- @click="buttonClick"
56
- >{{ buttonType ? defaultText : buttonText + "s" }}</el-button
57
- >
58
- </template>
59
-
60
- <style lang="less" scoped>
61
- .verifiaction-button {
62
- width: 109px;
63
- }
64
- </style>
@@ -1,30 +0,0 @@
1
- <!--
2
- * @Author: 陈德立*******419287484@qq.com
3
- * @Date: 2023-11-08 18:03:42
4
- * @LastEditTime: 2023-11-14 15:35:38
5
- * @LastEditors: 陈德立*******419287484@qq.com
6
- * @Github: https://github.com/Alan1034
7
- * @Description:
8
- * @FilePath: \GeneralBasicForm\src\components\VBasic\input-number\index.vue
9
- *
10
- -->
11
- <script setup lang="ts">
12
- import { inputDefaultSetting } from "../../setting";
13
- import { ref, inject } from "vue";
14
- import { BasicFormComponentsProps } from "../../../types/componentsProps";
15
- const { item } = defineProps<{item:any}>();
16
- const queryParams = inject("queryParams", {});
17
- const size = inject("size");
18
- const inputSetting = ref({
19
- ...inputDefaultSetting,
20
- ...item.inputSetting,
21
- });
22
- </script>
23
-
24
- <template>
25
- <el-input-number
26
- v-model="queryParams[item.prop]"
27
- :size="size"
28
- v-bind="inputSetting"
29
- />
30
- </template>
@@ -1,15 +0,0 @@
1
- /*
2
- * @Author: 陈德立*******419287484@qq.com
3
- * @Date: 2023-11-08 18:01:09
4
- * @LastEditTime: 2023-11-08 18:01:25
5
- * @LastEditors: 陈德立*******419287484@qq.com
6
- * @Github: https://github.com/Alan1034
7
- * @Description:
8
- * @FilePath: \GeneralBasicForm\src\components\setting.ts
9
- *
10
- */
11
- export const inputDefaultSetting = {
12
- placeholder: "请输入",
13
- style: "width: 200px",
14
- clearable: true,
15
- }
package/src/index.ts DELETED
@@ -1,15 +0,0 @@
1
- /*
2
- * @Author: 陈德立*******419287484@qq.com
3
- * @Date: 2021-08-20 17:05:30
4
- * @LastEditTime: 2023-11-07 15:05:39
5
- * @LastEditors: 陈德立*******419287484@qq.com
6
- * @Github: https://github.com/Alan1034
7
- * @Description:
8
- * @FilePath: \GeneralBasicForm\src\index.ts
9
- *
10
- */
11
-
12
- import GeneralBasicForm from './GeneralBasicForm.vue';
13
-
14
- export const VGeneralBasicForm = GeneralBasicForm
15
-
@@ -1,48 +0,0 @@
1
- export enum FormType {
2
- /**
3
- * @description: 输入框
4
- * @return {*}
5
- */
6
- 'input' = 'input',
7
- /**
8
- * @description: 输入框/图像验证码
9
- * @return {*}
10
- */
11
- 'input-graphic-verification' = 'input-graphic-verification',
12
- /**
13
- * @description: 输入框/手机验证码
14
- * @return {*}
15
- */
16
- 'input-mobile-verification' = 'input-mobile-verification',
17
- /**
18
- * @description: 分割线
19
- * @return {*}
20
- */
21
- 'divider' = 'divider',
22
- /**
23
- * @description: 选择器
24
- * @return {*}
25
- */
26
- 'select' = 'select',
27
- /**
28
- * @description: 级联选择器
29
- * @return {*}
30
- */
31
- 'cascader' = 'cascader',
32
- /**
33
- * @description: 日期选择器
34
- * @return {*}
35
- */
36
- 'date-picker' = 'date-picker',
37
- /**
38
- * @description: 数字输入框
39
- * @return {*}
40
- */
41
- 'input-number' = 'input-number',
42
- }
43
-
44
- export interface ItemType {
45
- type: FormType;
46
- // 扩展属性
47
- [key: string]: any
48
- };
@@ -1,17 +0,0 @@
1
-
2
- export interface BasicFormComponentsProps {
3
- item: any;
4
- // queryParams: Object | String;
5
- // size:String;
6
- // getList?:Function
7
- }
8
-
9
-
10
- export interface InputGraphicVerification {
11
- graphicSrc?: any
12
- getGraphic?: Function
13
- key: string | number
14
- };
15
- export interface InputMobileVerification {
16
- getSmscode: Function
17
- };
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "include": [
3
- "public/index.d.tsex.d.ts",
4
- "src/**/*",
5
- "src/**/*.vue",
6
- "public/*",
7
- ],
8
- "exclude": [],
9
- "compilerOptions": {
10
- "declaration": true,
11
- "allowJs": true,
12
- "composite": true
13
- }
14
- }