ol-base-components 0.2.2 → 0.3.1

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,2 +1,305 @@
1
1
  # base-component
2
- 二次封装的通用组件库。table,form
2
+
3
+ 二次封装的通用组件库,包含表格(Table)和表单(Form)等组件。
4
+
5
+ ## 安装
6
+
7
+ 您可以通过 npm 安装这个组件库:
8
+
9
+ ```bash
10
+ npm install ol-base-components
11
+ ```
12
+
13
+ ## 使用说明
14
+
15
+ 在您的 Vue 项目中,您需要在入口文件(通常是 `main.js` 或 `app.js`)中导入并使用该组件库:
16
+
17
+ ```javascript
18
+ // main.js
19
+ import Vue from "vue";
20
+ import App from "./App.vue";
21
+ import OlBaseComponents from "ol-base-components"; // 导入组件库
22
+
23
+ // 使用组件库
24
+ Vue.use(OlBaseComponents);
25
+
26
+ new Vue({
27
+ render: (h) => h(App),
28
+ }).$mount("#app");
29
+ ```
30
+
31
+ ## 组件示例
32
+
33
+ ### 搜索框组件
34
+
35
+ 您可以在您的组件中使用搜索框组件组件,例如:
36
+
37
+ ```vue
38
+ <template>
39
+ <div>
40
+ <ol-search
41
+ :form-search-data="formSearchData"
42
+ @handleSearch="handleSearch"
43
+ @handleReset="handleReset"
44
+ />
45
+ </div>
46
+ </template>
47
+
48
+ <script>
49
+ export default {
50
+ data() {
51
+ return {
52
+ formSearchData: {
53
+ reset: true,
54
+ expendShow: false,
55
+ value: {
56
+ WarehouseCode: null,
57
+ WarehouseName: null,
58
+ },
59
+ tableSearch: [
60
+ {
61
+ label: "仓库编码",
62
+ value: "WarehouseCode",
63
+ inputType: "text",
64
+ },
65
+ {
66
+ label: "仓库名称",
67
+ value: "WarehouseName",
68
+ inputType: "text",
69
+ },
70
+ ],
71
+ },
72
+ };
73
+ },
74
+ mounted() {
75
+ this.getTable();
76
+ },
77
+ method: {
78
+ getTable() {
79
+ // this.get({
80
+ // url: Basic.getWarehoseList,
81
+ // isLoading: true,
82
+ // data: Object.assign(this.formSearchData.value, {
83
+ // Page: this.paginations.page,
84
+ // MaxResultCount: this.paginations.limit,
85
+ // }),
86
+ // }).then((res) => {
87
+ // this.tableData.rows = res.result.items;
88
+ // this.paginations.total = res.result.totalCount;
89
+ // this.tableData.emptyImg = true;
90
+ // });
91
+ },
92
+ handleSearch(from) {
93
+ var self = this;
94
+ self.formSearchData.value = { ...from };
95
+ self.paginations.page = 1;
96
+ this.getTable(); // 获取表格数据
97
+ },
98
+ handleReset() {},
99
+ },
100
+ };
101
+ </script>
102
+ ```
103
+
104
+ ### 表格组件
105
+
106
+ 您可以在您的组件中使用表格组件组件,例如:
107
+
108
+ ```vue
109
+ <template>
110
+ <div>
111
+ <ol-table
112
+ :paginations="paginations"
113
+ :btnlist="this.hasBtn(this)"
114
+ :empty-img="tableData.emptyImg"
115
+ :table-data="tableData"
116
+ :multiple-selection="multipleSelection"
117
+ @SelectionChange="SelectionChange"
118
+ @handleSizeChange="handleSizeChange"
119
+ @handleindexChange="handleindexChange"
120
+ >
121
+ <template slot="classes" slot-scope="scope">
122
+ <div style="color: #1682e6; cursor: pointer" @click="config(scope)">
123
+ 设置
124
+ </div>
125
+ </template>
126
+ </ol-table>
127
+ </div>
128
+ </template>
129
+
130
+ <script>
131
+ export default {
132
+ data() {
133
+ return {
134
+ multipleSelection: [],
135
+ tableData: {
136
+ loading: false,
137
+ emptyImg: true,
138
+ options: {
139
+ selection: true, //多选框
140
+ index: null, //序号
141
+ headTool: true, //开启头部工具栏
142
+ refreshBtn: true, //开启表格头部刷新按钮
143
+ downloadBtn: true, //开启表格头部下载按钮
144
+ }, //序号和复选框
145
+ rows: [], //表数据
146
+ columns: [
147
+ {
148
+ label: "",
149
+ minWidth: "",
150
+ type: "selection",
151
+ show: true,
152
+ },
153
+ {
154
+ prop: "warehouseCode",
155
+ label: "仓库编码",
156
+ minWidth: "",
157
+ sortable: false,
158
+ show: true,
159
+ },
160
+ {
161
+ prop: "warehouseName",
162
+ label: "仓库名称",
163
+ minWidth: "",
164
+ sortable: false,
165
+ show: true,
166
+ },
167
+ {
168
+ prop: "enabledDesc",
169
+ label: "状态",
170
+ minWidth: "",
171
+ sortable: false,
172
+ show: true,
173
+ },
174
+ {
175
+ prop: "createdUser",
176
+ label: "创建人",
177
+ minWidth: "",
178
+ sortable: false,
179
+ show: true,
180
+ },
181
+ {
182
+ prop: "createTime",
183
+ label: "创建时间",
184
+ minWidth: "",
185
+ show: true,
186
+ },
187
+ {
188
+ prop: "classes",
189
+ label: "班次",
190
+ minWidth: "",
191
+ show: true,
192
+ renderSlot: true,
193
+ },
194
+ {
195
+ prop: "remark",
196
+ label: "备注",
197
+ minWidth: "",
198
+ show: true,
199
+ },
200
+ ], //表头
201
+ operates: [], //表格里面的操作按钮
202
+ tableHeightDiff: 300,
203
+ },
204
+ paginations: {
205
+ page: 1, //当前位于那页面
206
+ total: 10, //总数
207
+ limit: 30, //一页显示多少条
208
+ pagetionShow: true,
209
+ },
210
+ };
211
+ },
212
+ methods: {
213
+ SelectionChange(row) {
214
+ this.multipleSelection = row;
215
+ },
216
+ handleSizeChange(val) {
217
+ this.paginations.page = 1;
218
+ this.paginations.limit = val;
219
+ this.getTable();
220
+ },
221
+ handleindexChange(val) {
222
+ this.paginations.page = val;
223
+ this.getTable();
224
+ },
225
+ },
226
+ };
227
+ </script>
228
+ ```
229
+
230
+ ### 表单弹框组件
231
+
232
+ 您可以在您的组件中使用表单弹框组件组件,例如:
233
+
234
+ ```vue
235
+ <template>
236
+ <div>
237
+ <ol-dialogTemplate :form="form" />
238
+ </ol-table>
239
+ </div>
240
+ </template>
241
+
242
+ <script>
243
+ export default {
244
+ data() {
245
+ return {
246
+ form: {
247
+ dialogFormVisible: false,
248
+ title: "",
249
+ model: [
250
+
251
+ {
252
+ label: "字典编码",
253
+ type: "input",
254
+ prop: "code",
255
+ },
256
+ {
257
+ label: "字典名称",
258
+ type: "input",
259
+ prop: "displayName",
260
+ },
261
+
262
+ // {
263
+ // label: "启用",
264
+ // type: "switch",
265
+ // prop: "enabled",
266
+ // },
267
+
268
+ {
269
+ label: "备注",
270
+ type: "textarea",
271
+ prop: "remark",
272
+ },
273
+ ],
274
+ rules: {
275
+ displayName: [{ required: true, message: "必填", trigger: "blur" }],
276
+ code: [{ required: true, message: "必填", trigger: "blur" }],
277
+ },
278
+ value: {
279
+ code: "",
280
+ displayName: "",
281
+ // enabled: true,
282
+ remark: "",
283
+ },
284
+ requestData: {
285
+ flage: "add",
286
+ url: PublicAggregate.dictionaries,
287
+ fn: this.getTable,
288
+ },
289
+ },
290
+ };
291
+ },
292
+ methods: {
293
+
294
+ },
295
+ };
296
+ </script>
297
+ ```
298
+
299
+ ## 贡献
300
+
301
+ 欢迎任何形式的贡献!如果您有建议或发现问题,请提交 issue 或 pull request。
302
+
303
+ ## License
304
+
305
+ MIT License
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.1",
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
  // 遍历所有组件