general-basic-form 1.0.11 → 1.0.15

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # GeneralBasicForm
2
2
 
3
- 一个兼容Vue2和Vue3的表单组件 <br/>
3
+ 一个兼容 Vue2 Vue3 的表单组件 <br/>
4
4
  示例:
5
5
 
6
6
  <GeneralBasicForm
@@ -16,12 +16,48 @@
16
16
 
17
17
  ![image-20210903165502942](https://raw.githubusercontent.com/Alan1034/PicturesServer/main/PicGo_imgs/202109031655830.png)
18
18
 
19
+ 在单纯作为表单的时候可以这样使用:
20
+
21
+ <GeneralBasicForm
22
+ formOnly
23
+ :formItem="formItem"
24
+ size="small"
25
+ ref="generalBasicForm"
26
+ :labelWidth="formLabelWidth"
27
+ noUrlParameters
28
+ />
29
+
30
+ <style lang="scss" scoped>
31
+ :deep {
32
+ .el-form-item {
33
+ margin-bottom: 22px;
34
+ }
35
+ }
36
+ </style>
37
+
38
+ ![image-20211014191532067](https://raw.githubusercontent.com/Alan1034/PicturesServer/main/PicGo_imgs/202110141915657.png)
39
+
19
40
  数据示例:
20
41
 
21
42
  showSearch: true, // 显示搜索条件
22
- getList(); //请求数据的函数
23
- formItem: [
24
- { label: "款式名称", prop: "bsName", type: "input", placeholder: "请输入图片名称/分类名称/图片标签", },
43
+ getList(); // 请求数据的函数
44
+ formOnly:true // 只展示表单不展示按钮
45
+ noUrlParameters:true // 不接受和不改变url的参数
46
+ formItem: [
47
+ { label: "款式名称",
48
+ prop: "bsName",
49
+ type: "input",
50
+ placeholder: "请输入图片名称/分类名称/图片标签",
51
+ rules: [
52
+ {
53
+ message: "请输入信息"
54
+ },
55
+ {
56
+ pattern: /^\w+[\,\,\-\w' '#]+$/,
57
+ message: "请输入正确的Invoice单号"
58
+ }
59
+ ],
60
+ maxlength: "3000"},
25
61
  {
26
62
  label: "二次工艺",
27
63
  prop: "spName",
@@ -32,7 +68,11 @@
32
68
  { value: "2", desc: "绣花" },
33
69
  ],
34
70
  },
35
- { label: "创建时间", prop: "create_time", type: "date-picker"
71
+ {
72
+ label: "创建时间",
73
+ prop: "create_time",
74
+ type: "date-picker",
75
+ "value-format": "yyyyMMdd"
36
76
  },
37
77
  {
38
78
  label: "分类",
@@ -104,6 +144,7 @@
104
144
  ],
105
145
  //分别支持input输入框,select单选框,date-picker日期选择器,cascader层级选择器 四种组件
106
146
  //date-picker可以传入'start-placeholder'和'end-placeholder',其他组件支持placeholder传入
147
+ //rules为表单校验规则,每个组件都可以传入
107
148
 
108
149
  安装:npm i general-basic-form<br/>
109
150
  install: npm i general-basic-form
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "general-basic-form",
3
- "version": "1.0.11",
3
+ "version": "1.0.15",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -1,7 +1,7 @@
1
1
  <!--
2
2
  * @Author: 陈德立*******419287484@qq.com
3
3
  * @Date: 2021-08-20 17:14:53
4
- * @LastEditTime: 2021-09-03 16:58:34
4
+ * @LastEditTime: 2021-10-16 15:06:06
5
5
  * @LastEditors: 陈德立*******419287484@qq.com
6
6
  * @Github: https://github.com/Alan1034
7
7
  * @Description:
@@ -25,6 +25,7 @@
25
25
  :label="item.label"
26
26
  :prop="item.prop"
27
27
  :key="item.prop"
28
+ :rules="item.rules"
28
29
  >
29
30
  <el-input
30
31
  v-if="item.type === 'input'"
@@ -33,6 +34,7 @@
33
34
  :size="size"
34
35
  v-bind="inputSetting"
35
36
  :placeholder="item.placeholder || inputSetting.placeholder"
37
+ :maxlength="item.maxlength"
36
38
  ></el-input>
37
39
  <el-select
38
40
  filterable
@@ -69,9 +71,10 @@
69
71
  :end-placeholder="
70
72
  item['end-placeholder'] || datePackerSetting['end-placeholder']
71
73
  "
74
+ :value-format="item['value-format']"
72
75
  ></el-date-picker>
73
76
  </el-form-item>
74
- <el-form-item>
77
+ <el-form-item v-if="!formOnly">
75
78
  <el-button
76
79
  type="primary"
77
80
  icon="el-icon-search"
@@ -92,14 +95,22 @@ export default {
92
95
  name: "GeneralBasicForm",
93
96
  props: {
94
97
  showSearch: {
98
+ // 是否展示所有元素
95
99
  type: Boolean,
96
100
  default: true,
97
101
  },
102
+ formOnly: {
103
+ // 是否只展示表单不展示按钮
104
+ type: Boolean,
105
+ default: false,
106
+ },
98
107
  getList: {
108
+ // 查找数据调用的函数
99
109
  type: Function,
100
110
  default: () => {},
101
111
  },
102
112
  formItem: {
113
+ // 定义表单的数据
103
114
  type: Array,
104
115
  default: [],
105
116
  },
@@ -113,10 +124,22 @@ export default {
113
124
  type: String,
114
125
  default: "90px",
115
126
  },
127
+ noUrlParameters: {
128
+ // 不接受和不改变url的参数
129
+ type: Boolean,
130
+ default: () => false,
131
+ },
132
+ formData: {
133
+ // 外部传入的表单数据,用于回填
134
+ type: Object,
135
+ default: {},
136
+ },
116
137
  },
117
138
  data() {
118
139
  return {
119
- queryParams: { ...this.$route?.query },
140
+ queryParams: {
141
+ ...(this.noUrlParameters ? {} : this.$route?.query),
142
+ }, // form表单数据
120
143
  selectSetting: {
121
144
  placeholder: "请选择",
122
145
  clearable: true,
@@ -149,6 +172,14 @@ export default {
149
172
  // queryParams,
150
173
  // };
151
174
  // },
175
+ watch: {
176
+ formData(val) {
177
+ this.queryParams = {
178
+ ...(this.noUrlParameters ? {} : this.queryParams),
179
+ ...val,
180
+ };
181
+ },
182
+ },
152
183
  methods: {
153
184
  /** 搜索按钮操作 */
154
185
  handleQuery() {
@@ -158,20 +189,24 @@ export default {
158
189
  ...this.queryParams,
159
190
  ...params,
160
191
  };
161
- this.$router.push({
162
- query: { ...searchParams },
163
- });
192
+ if (!this.noUrlParameters) {
193
+ this.$router.push({
194
+ query: { ...searchParams },
195
+ });
196
+ }
164
197
  this.getList({
165
198
  ...searchParams,
166
199
  });
167
200
  },
168
201
  /** 重置按钮操作 */
169
- resetQuery() {
202
+ async resetQuery() {
170
203
  this.$refs.queryFormRef.resetFields();
171
204
  const params = { page: 1 };
172
- this.$router.push({
173
- query: { ...params },
174
- });
205
+ if (!this.noUrlParameters) {
206
+ await this.$router.push({
207
+ query: { ...params },
208
+ });
209
+ }
175
210
  this.handleQuery();
176
211
  },
177
212
  },