ol-base-components 0.2.2 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ol-base-components",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "private": false,
5
5
  "main": "src/package/index.js",
6
6
  "scripts": {
@@ -0,0 +1,7 @@
1
+ import Dialog from "./src/index.vue";
2
+
3
+ Dialog.install = function (Vue) {
4
+ Vue.component("ol-dialogTemplate ", Dialog);
5
+ };
6
+
7
+ export default Dialog;
@@ -0,0 +1,419 @@
1
+ <template>
2
+ <div>
3
+ <el-dialog
4
+ v-el-drag-dialog
5
+ :title="gettitle"
6
+ :visible.sync="form.dialogFormVisible"
7
+ :close-on-click-modal="false"
8
+ :width="form.width || '45%'"
9
+ :show-close="true"
10
+ top="5vh"
11
+ @close="resetForm('form')"
12
+ @open="handleOpen('form')"
13
+ >
14
+ <el-form
15
+ ref="form"
16
+ :model="form.value"
17
+ :rules="form.rules"
18
+ label-width="130px"
19
+ style="display: flex; flex-wrap: wrap"
20
+ >
21
+ <el-form-item
22
+ v-for="(item, index) in form.model"
23
+ :key="index"
24
+ :label="item.label"
25
+ :prop="item.prop"
26
+ :required="item.required || false"
27
+ :style="{ width: width(item) }"
28
+ >
29
+ <el-input
30
+ v-if="item.type == 'input'"
31
+ v-model="form.value[item.prop]"
32
+ :placeholder="
33
+ item.readonly
34
+ ? item.placeholder || item.label
35
+ : `请输入${item.placeholder || item.label}`
36
+ "
37
+ :clearable="item.clearable || true"
38
+ :readonly="item.readonly || false"
39
+ :disabled="item.disabled || false"
40
+ :show-password="item.showPassword || false"
41
+ />
42
+ <el-input-number
43
+ v-if="item.type == 'number'"
44
+ v-model="form.value[item.prop]"
45
+ :placeholder="`请输入${item.placeholder || item.label}`"
46
+ :clearable="item.clearable || true"
47
+ :readonly="item.readonly || false"
48
+ :min="item.props.min || 0"
49
+ v-bind="item.props || {}"
50
+ />
51
+ <el-input
52
+ v-if="item.type == 'textarea'"
53
+ v-model="form.value[item.prop]"
54
+ type="textarea"
55
+ :placeholder="`请输入${item.placeholder || item.label}`"
56
+ :autosize="item.autosize"
57
+ :readonly="item.readonly || false"
58
+ :clearable="item.clearable || true"
59
+ :maxlength="item.length || ''"
60
+ />
61
+ <el-switch
62
+ v-if="item.type == 'switch'"
63
+ v-model="form.value[item.prop]"
64
+ class="switchStyle"
65
+ active-text="启用"
66
+ inactive-text="禁用"
67
+ />
68
+ <el-radio-group
69
+ v-if="item.type == 'radio'"
70
+ v-model="form.value[item.prop]"
71
+ >
72
+ <el-radio
73
+ v-for="(ctem, cindex) in item.child"
74
+ :key="ctem.key"
75
+ :label="ctem.key"
76
+ >{{ ctem.value }}</el-radio
77
+ >
78
+ </el-radio-group>
79
+ <el-date-picker
80
+ v-if="item.type == 'date'"
81
+ v-model="form.value[item.prop]"
82
+ v-bind="item.props || { type: 'date' }"
83
+ :placeholder="item.placeholder || '请选择日期'"
84
+ style="width: 100%"
85
+ :clearable="item.clearable || true"
86
+ />
87
+ <Tree-select
88
+ v-if="item.type == 'treeSelect'"
89
+ v-model="form.value[item.prop]"
90
+ v-bind="item.props || {}"
91
+ :options="item.child"
92
+ @getValue="item.change && item.change(form.value[item.prop])"
93
+ />
94
+ <!-- @change="
95
+ item.change
96
+ ? item.change(form.value[item.prop])
97
+ : selectChange(item, form.value[item.prop])
98
+ " -->
99
+ <el-select
100
+ v-if="item.type == 'select'"
101
+ v-model="form.value[item.prop]"
102
+ :placeholder="`请选择${item.placeholder || item.label}`"
103
+ :clearable="'clearable' in item ? item.clearable : true"
104
+ :disabled="item.disabled || false"
105
+ v-bind="item.props || {}"
106
+ v-on="{
107
+ ...(item.listeners || {}),
108
+ change: () => selectChangeHandler(item, form.value[item.prop]),
109
+ }"
110
+ >
111
+ <el-option
112
+ v-for="(jtem, jindex) in item.child"
113
+ :key="jindex"
114
+ :label="jtem.value"
115
+ :value="jtem.key"
116
+ />
117
+ </el-select>
118
+ <div v-if="item.type == 'inputSpecial'">
119
+ <el-col :span="6">
120
+ <el-form-item :prop="item.layerprop">
121
+ <el-input
122
+ v-model="form.value[item.layerprop]"
123
+ :clearable="item.clearable || true"
124
+ />
125
+ </el-form-item>
126
+ </el-col>
127
+ <el-col class="line" style="text-align: center" :span="3"
128
+ >-
129
+ </el-col>
130
+ <el-col :span="6">
131
+ <el-form-item :prop="item.rowprop">
132
+ <el-input
133
+ v-model="form.value[item.rowprop]"
134
+ :clearable="item.clearable || true"
135
+ />
136
+ </el-form-item>
137
+ </el-col>
138
+ <el-col class="line" style="text-align: center" :span="3"
139
+ >-
140
+ </el-col>
141
+ <el-col :span="6">
142
+ <el-form-item :prop="item.columnprop">
143
+ <el-input
144
+ v-model="form.value[item.columnprop]"
145
+ :clearable="item.clearable || true"
146
+ />
147
+ </el-form-item>
148
+ </el-col>
149
+ </div>
150
+ <!-- 自定义输入框插槽 -->
151
+ <template v-if="item.type == 'slot'">
152
+ <slot :name="item.name" :item="item" />
153
+ </template>
154
+ </el-form-item>
155
+ </el-form>
156
+ <div slot="footer" class="dialog-footer">
157
+ <el-button @click="resetForm('form')">取 消</el-button>
158
+ <el-button
159
+ v-if="form.requestData.methodsType != 'get'"
160
+ type="primary"
161
+ @click="submitForm('form')"
162
+ >确 定
163
+ </el-button>
164
+ </div>
165
+ </el-dialog>
166
+ </div>
167
+ </template>
168
+ <script>
169
+ /**
170
+ * 参数
171
+ * dialogFormVisible:false,//弹窗显示
172
+ * title:'',//标题
173
+ * width:'',//弹窗宽度
174
+ model:[{
175
+ label: "test",
176
+ type: "input",
177
+ prop: "code",
178
+ }],//表单数据
179
+ rules:[],//表单规则
180
+ value:{},//双向绑定的值
181
+ requestData:{},//接口地址及传参的数据
182
+ */
183
+ export default {
184
+ name: "dialogTemplate",
185
+ props: {
186
+ form: Object,
187
+ },
188
+ data() {
189
+ return {};
190
+ },
191
+ computed: {
192
+ width() {
193
+ return function (item) {
194
+ if (this.form.model.length > 18 && item.type != "textarea") {
195
+ return "25%";
196
+ } else if (
197
+ this.form.model.length > 10 &&
198
+ this.form.model.length <= 18 &&
199
+ item.type != "textarea"
200
+ ) {
201
+ return "calc(100% / 3)";
202
+ } else if (
203
+ this.form.model.length > 6 &&
204
+ this.form.model.length <= 10 &&
205
+ item.type != "textarea"
206
+ ) {
207
+ return "50%";
208
+ } else {
209
+ return item.type == "textarea" && item.width ? item.width : "100%";
210
+ }
211
+ };
212
+ },
213
+ gettitle() {
214
+ // 如果传入是
215
+ if (this.form.title && !this.form.titleAdd) {
216
+ return this.form.title;
217
+ } else if (this.form.titleAdd) {
218
+ if (this.form.requestData.flage == "add") {
219
+ return "添加";
220
+ } else {
221
+ return "编辑";
222
+ }
223
+ } else {
224
+ return "提示";
225
+ }
226
+ },
227
+ },
228
+ methods: {
229
+ selectChangeHandler(item, val) {
230
+ if (item.change) {
231
+ item.change(this.form.value[item.prop]);
232
+ } else if (item.listeners && item.listeners.change) {
233
+ item.listeners.change(item, this.form.value[item.prop]);
234
+ } else {
235
+ this.selectChange(item, this.form.value[item.prop]);
236
+ }
237
+ },
238
+ selectChange(obj, val) {
239
+ let temp = {
240
+ obj: obj,
241
+ val: val,
242
+ };
243
+ this.$emit("selectChange", temp);
244
+ },
245
+
246
+ submitForm(formName) {
247
+ console.log("form", this.form);
248
+
249
+ this.$refs[formName].validate((valid) => {
250
+ if (valid) {
251
+ /**
252
+ * 翻包工位配置 特殊处理业务
253
+ */
254
+ if (this.form.requestData.specialFn) {
255
+ if (!this.form.value.businessType && !this.form.value.boxModel) {
256
+ return this.$message.error("业务类型和空容器型号必填一个");
257
+ }
258
+ }
259
+ /**
260
+ * 质检单 - 质检单明细
261
+ */
262
+ if (this.form.requestData.flage == "zjDetail") {
263
+ return this.$emit("newRequest", this.form.value);
264
+ }
265
+ if (this.form.requestData.flage == "update") {
266
+ this.put({
267
+ url: this.form.requestData.url + "/" + this.form.value.id,
268
+ data: this.form.value,
269
+ isLoading: true,
270
+ }).then((res) => {
271
+ this.form.requestData.fn();
272
+ this.form.dialogFormVisible = false;
273
+ this.$message({
274
+ type: "success",
275
+ message: "操作成功!",
276
+ });
277
+ });
278
+ } else {
279
+ /**
280
+ * flage == "autoArrange"
281
+ * 弹框方法不用内部 用外部方法
282
+ */
283
+ if (this.form.requestData.flage == "autoArrange") {
284
+ return this.$emit("submitForm", "form");
285
+ }
286
+ /**
287
+ * 默认请求地址
288
+ */
289
+ let url = this.form.requestData.url;
290
+ /**
291
+ * task 页面路径名字
292
+ * 特殊页面 弹框标识 flages 参数接在url 后面
293
+ */
294
+ if (this.form.requestData.flages) {
295
+ let joinData = this.form.requestData.joinData;
296
+ let str = "";
297
+ for (let i = 0; i < joinData.length; i++) {
298
+ str += `${i == 0 ? "?" : "&"}${joinData[i]}=${
299
+ this.form.value[joinData[i]]
300
+ }`;
301
+ }
302
+ url = this.form.requestData.url + str;
303
+ }
304
+ /**
305
+ * 弹框可能是get请求
306
+ */
307
+ if (
308
+ this.form.requestData.methodsType &&
309
+ this.form.requestData.methodsType == "get"
310
+ ) {
311
+ return this.get({
312
+ url: url,
313
+ data: this.form.value,
314
+ isLoading: true,
315
+ }).then((res) => {
316
+ this.form.requestData.fn();
317
+ this.form.dialogFormVisible = false;
318
+ this.$message({
319
+ type: "success",
320
+ message: "操作成功!",
321
+ });
322
+ });
323
+ }
324
+ /**
325
+ * 弹框可能是post请求
326
+ * 默认
327
+ */
328
+ this.post({
329
+ url: url,
330
+ data: this.form.value,
331
+ isLoading: true,
332
+ }).then((res) => {
333
+ this.form.requestData.fn();
334
+ this.form.dialogFormVisible = false;
335
+ this.$message({
336
+ type: "success",
337
+ message: "操作成功!",
338
+ });
339
+ });
340
+ }
341
+ } else {
342
+ console.log("error submit!!");
343
+ return false;
344
+ }
345
+ });
346
+ },
347
+ closeD(formName) {
348
+ this.form.dialogFormVisible = false;
349
+ },
350
+ resetForm(formName) {
351
+ this.$emit("close");
352
+ if (this.form.requestData.flage == "autoArrange") {
353
+ return this.$emit("resetForm");
354
+ }
355
+ this.$refs[formName].resetFields();
356
+ this.form.dialogFormVisible = false;
357
+ },
358
+ handleOpen(formName) {
359
+ this.$nextTick(() => {
360
+ this.$refs[formName].clearValidate();
361
+ });
362
+ },
363
+ },
364
+ };
365
+ </script>
366
+ <style lang="scss">
367
+ .el-dialog__header {
368
+ background-color: #008cff !important;
369
+ padding: 10px 15px;
370
+ text-align: left;
371
+ .el-dialog__title,
372
+ .el-dialog__headerbtn i {
373
+ color: white;
374
+ }
375
+ }
376
+ .el-dialog__body {
377
+ padding: 25px 20px;
378
+ }
379
+ .el-dialog__close {
380
+ cursor: pointer !important;
381
+ font-size: 20px !important;
382
+ position: relative !important;
383
+ top: -11px !important;
384
+ color: #fff !important;
385
+ border-radius: 50% !important;
386
+ text-align: center !important;
387
+ height: 30px !important;
388
+ width: 30px !important;
389
+ line-height: 30px !important;
390
+ vertical-align: middle !important;
391
+ right: -13px !important;
392
+ }
393
+ .el-select,
394
+ .el-input-number {
395
+ width: 100% !important;
396
+ }
397
+ .activeWidth {
398
+ width: 50% !important;
399
+ }
400
+ .switchStyle .el-switch__label {
401
+ position: absolute;
402
+ display: none;
403
+ color: #fff;
404
+ }
405
+ .switchStyle .el-switch__label--left {
406
+ z-index: 9;
407
+ left: 20px;
408
+ }
409
+ .switchStyle .el-switch__label--right {
410
+ z-index: 9;
411
+ }
412
+ .switchStyle .el-switch__label.is-active {
413
+ display: block;
414
+ }
415
+ .switchStyle.el-switch .el-switch__core,
416
+ .el-switch .el-switch__label {
417
+ width: 60px !important;
418
+ }
419
+ </style>
@@ -1,7 +1,8 @@
1
1
  import OlTable from "./table";
2
2
  import OlSearch from "./formSearch";
3
+ import Dialog from "./dialog";
3
4
 
4
- const components = [OlTable, OlSearch];
5
+ const components = [OlTable, OlSearch, Dialog];
5
6
 
6
7
  const install = function (Vue) {
7
8
  // 遍历所有组件