ol-base-components 2.8.19 → 2.9.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/src/api/init.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  // 就是执行api.js和run.js脚本 npx init http://xxxx
3
3
  const { spawn } = require("child_process");
4
4
  const path = require("path");
package/src/api/run.js CHANGED
@@ -141,8 +141,6 @@ function cleanSummary(summary) {
141
141
  }
142
142
  // 生成API模块
143
143
  const generateApiModules = swagger => {
144
- console.log(2222, swagger);
145
-
146
144
  const { tags, paths } = swagger;
147
145
  const apiModules = {};
148
146
  // 初始化模块对象
@@ -185,7 +185,7 @@ const vue2Template = (moduleName, config = {}) => {
185
185
  Author:
186
186
  -->
187
187
  <template>
188
- <div>
188
+ <div class="ol-container">
189
189
  <ol-search
190
190
  :url="swaggerUrl.${pageUrlKey}"
191
191
  :form-search-data="formSearchData"
@@ -124,6 +124,13 @@
124
124
  :value="jtem.key"
125
125
  />
126
126
  </el-select>
127
+ <ol-number-range
128
+ v-else-if="item.type === 'numberRange'"
129
+ v-model="form.value[item.prop]"
130
+ v-bind="item.props || {}"
131
+ v-on="{ ...item.listeners, change: val => item.listeners?.change({ item, val }) }"
132
+ ></ol-number-range>
133
+
127
134
  <div v-else-if="item.type == 'inputSpecial'">
128
135
  <el-col :span="6">
129
136
  <el-form-item :prop="item.layerprop">
@@ -212,6 +219,7 @@
212
219
  -->
213
220
  <script>
214
221
  import { initForm } from "../../../utils/initData.js";
222
+ import OlNumberRange from "../../numberRange/index.js";
215
223
 
216
224
  // interface FormItem {
217
225
  // type: Number;
@@ -222,6 +230,9 @@ import { initForm } from "../../../utils/initData.js";
222
230
  // }
223
231
  export default {
224
232
  name: "form",
233
+ components: {
234
+ OlNumberRange,
235
+ },
225
236
  props: {
226
237
  url: {
227
238
  type: String,
@@ -109,6 +109,12 @@
109
109
  v-bind="item.props || { type: 'date' }"
110
110
  :default-time="item.props.type == 'datetimerange' ? ['00:00:00', '23:59:59'] : ''"
111
111
  />
112
+ <ol-number-range
113
+ v-else-if="item.inputType === 'numberRange'"
114
+ v-model="formSearch[item.value]"
115
+ v-bind="item.props || {}"
116
+ v-on="{ ...item.listeners, change: val => item.listeners?.change({ item, val }) }"
117
+ ></ol-number-range>
112
118
  <el-input
113
119
  v-else
114
120
  v-model="formSearch[item.value]"
@@ -177,10 +183,14 @@
177
183
  <script>
178
184
  import { getData } from "../../index.js";
179
185
  import { getEnum } from "../../../utils/getEnum.js";
186
+ import OlNumberRange from "../../numberRange/index.js";
180
187
  import { camelCaseToChinese } from "./index.js";
181
188
 
182
189
  export default {
183
190
  name: "search",
191
+ components: {
192
+ OlNumberRange,
193
+ },
184
194
  directives: {
185
195
  "el-select-loadmore": {
186
196
  bind(el, binding) {
@@ -2,6 +2,8 @@ import OlTable from "./table";
2
2
  import OlSearch from "./formSearch";
3
3
  import Dialog from "./dialog";
4
4
  import OlForm from "./form";
5
+ import OlNumberRange from "./numberRange";
6
+
5
7
  import SwaggerClient from "swagger-client";
6
8
 
7
9
  const consoleTooltip = () => {
@@ -53,16 +55,16 @@ function openDatabase() {
53
55
  return new Promise((resolve, reject) => {
54
56
  const request = indexedDB.open(DB_NAME, DB_VERSION);
55
57
 
56
- request.onupgradeneeded = (event) => {
58
+ request.onupgradeneeded = event => {
57
59
  const db = event.target.result;
58
60
  db.createObjectStore(STORE_NAME);
59
61
  };
60
62
 
61
- request.onsuccess = (event) => {
63
+ request.onsuccess = event => {
62
64
  resolve(event.target.result);
63
65
  };
64
66
 
65
- request.onerror = (event) => {
67
+ request.onerror = event => {
66
68
  reject(event.target.error);
67
69
  };
68
70
  });
@@ -70,30 +72,30 @@ function openDatabase() {
70
72
 
71
73
  // 存储数据
72
74
  function storeData(data) {
73
- return openDatabase().then((db) => {
75
+ return openDatabase().then(db => {
74
76
  return new Promise((resolve, reject) => {
75
77
  const transaction = db.transaction(STORE_NAME, "readwrite");
76
78
  const store = transaction.objectStore(STORE_NAME);
77
79
  store.put(data, "swaggerData"); // 使用 'swaggerData' 作为键
78
80
  transaction.oncomplete = () => resolve();
79
- transaction.onerror = (event) => reject(event.target.error);
81
+ transaction.onerror = event => reject(event.target.error);
80
82
  });
81
83
  });
82
84
  }
83
85
 
84
86
  // 获取数据
85
87
  export function getData() {
86
- return openDatabase().then((db) => {
88
+ return openDatabase().then(db => {
87
89
  return new Promise((resolve, reject) => {
88
90
  const transaction = db.transaction(STORE_NAME, "readonly");
89
91
  const store = transaction.objectStore(STORE_NAME);
90
92
  const request = store.get("swaggerData");
91
93
 
92
- request.onsuccess = (event) => {
94
+ request.onsuccess = event => {
93
95
  resolve(event.target.result);
94
96
  };
95
97
 
96
- request.onerror = (event) => {
98
+ request.onerror = event => {
97
99
  reject(event.target.error);
98
100
  };
99
101
  });
@@ -102,19 +104,19 @@ export function getData() {
102
104
 
103
105
  // 清除数据
104
106
  function clearData() {
105
- return openDatabase().then((db) => {
107
+ return openDatabase().then(db => {
106
108
  return new Promise((resolve, reject) => {
107
109
  const transaction = db.transaction(STORE_NAME, "readwrite");
108
110
  const store = transaction.objectStore(STORE_NAME);
109
111
  store.delete("swaggerData"); // 删除存储的数据
110
112
  transaction.oncomplete = () => resolve();
111
- transaction.onerror = (event) => reject(event.target.error);
113
+ transaction.onerror = event => reject(event.target.error);
112
114
  });
113
115
  });
114
116
  }
115
117
 
116
118
  // 注册
117
- const swaggerInstall = async (swaggerUrl) => {
119
+ const swaggerInstall = async swaggerUrl => {
118
120
  if (!swaggerUrl) return Promise.reject(new Error("Swagger URL is required.")); // 检查 Swagger URL
119
121
 
120
122
  // IndexedDB 获取 Swagger 数据
@@ -144,7 +146,6 @@ const swaggerUnload = async function () {
144
146
  await clearData(); // 清空 IndexedDB 中的缓存数据
145
147
  };
146
148
 
147
-
148
149
  // 自定义加载指示器
149
150
  function showLoading() {
150
151
  const style = document.createElement("style");
@@ -203,16 +204,15 @@ function hideLoading() {
203
204
  }
204
205
  }
205
206
 
206
-
207
- const components = [OlTable, OlSearch, Dialog, OlForm];
207
+ const components = [OlTable, OlSearch, Dialog, OlForm, OlNumberRange];
208
208
  const install = async function (Vue) {
209
209
  // 设置全局数据
210
- components.map((item) => {
210
+ components.map(item => {
211
211
  Vue.component(`ol-${item.name}`, item);
212
212
  });
213
213
  consoleTooltip();
214
214
  };
215
215
 
216
216
  export default install;
217
- export { OlTable, OlSearch, Dialog, OlForm };
217
+ export { OlTable, OlSearch, Dialog, OlForm, OlNumberRange };
218
218
  export { swaggerInstall, swaggerUnload };
@@ -0,0 +1,7 @@
1
+ import OlNumberRange from "./src/index.vue";
2
+
3
+ OlNumberRange.install = function (Vue) {
4
+ Vue.component("ol-number-range ", OlNumberRange);
5
+ };
6
+
7
+ export default OlNumberRange;
@@ -0,0 +1,351 @@
1
+ <template>
2
+ <div class="ol-number-range" :class="{ 'is-disabled': disabled }">
3
+ <el-input
4
+ ref="startInput"
5
+ v-model="startValue"
6
+ type="number"
7
+ :placeholder="startPlaceholder"
8
+ :min="min"
9
+ :max="max"
10
+ :disabled="disabled"
11
+ class="range-input start-input"
12
+ @blur="handleStartBlur"
13
+ @input="handleStartInput"
14
+ @keyup.enter.native="handleStartBlur"
15
+ />
16
+ <span class="range-separator">-</span>
17
+ <el-input
18
+ ref="endInput"
19
+ v-model="endValue"
20
+ type="number"
21
+ :placeholder="endPlaceholder"
22
+ :min="min"
23
+ :max="max"
24
+ :disabled="disabled"
25
+ class="range-input end-input"
26
+ @blur="handleEndBlur"
27
+ @input="handleEndInput"
28
+ @keyup.enter.native="handleEndBlur"
29
+ />
30
+ <i
31
+ v-if="clearable && !disabled && (startValue || endValue)"
32
+ class="el-icon-circle-close clear-icon"
33
+ @click="handleClear"
34
+ />
35
+ </div>
36
+ </template>
37
+
38
+ <script>
39
+ export default {
40
+ name: "NumberRange",
41
+ props: {
42
+ value: {
43
+ type: Array,
44
+ default: () => [null, null],
45
+ },
46
+ min: {
47
+ type: Number,
48
+ default: 0,
49
+ },
50
+ max: {
51
+ type: Number,
52
+ default: 999999,
53
+ },
54
+ startPlaceholder: {
55
+ type: String,
56
+ default: "起始值",
57
+ },
58
+ endPlaceholder: {
59
+ type: String,
60
+ default: "终止值",
61
+ },
62
+ clearable: {
63
+ type: Boolean,
64
+ default: true,
65
+ },
66
+ // 是否启用默认填充最大最小值
67
+ autoFillDefault: {
68
+ type: Boolean,
69
+ default: false,
70
+ },
71
+ disabled: {
72
+ type: Boolean,
73
+ default: false,
74
+ },
75
+ // 数值精度,类似el-input-Number组件precision
76
+ precision: {
77
+ type: Number,
78
+ default: 0,
79
+ validator(val) {
80
+ return val === undefined || (Number.isInteger(val) && val >= 0);
81
+ },
82
+ },
83
+ },
84
+ data() {
85
+ return {
86
+ startValue: null,
87
+ endValue: null,
88
+ };
89
+ },
90
+ watch: {
91
+ value: {
92
+ handler(newVal) {
93
+ if (Array.isArray(newVal) && newVal.length === 2) {
94
+ this.startValue =
95
+ newVal[0] !== null && newVal[0] !== undefined
96
+ ? this.formatPrecision(Number(newVal[0]))
97
+ : null;
98
+ this.endValue =
99
+ newVal[1] !== null && newVal[1] !== undefined
100
+ ? this.formatPrecision(Number(newVal[1]))
101
+ : null;
102
+ } else {
103
+ this.startValue = null;
104
+ this.endValue = null;
105
+ }
106
+ },
107
+ immediate: true,
108
+ deep: true,
109
+ },
110
+ },
111
+ methods: {
112
+ // 格式化精度
113
+ formatPrecision(num) {
114
+ if (this.precision !== undefined && this.precision !== null) {
115
+ return Number(Number(num).toFixed(this.precision));
116
+ }
117
+ return num;
118
+ },
119
+ // 处理起始值输入
120
+ handleStartInput(val) {
121
+ if (this.disabled) return;
122
+ if (val === "" || val === null || val === undefined) {
123
+ this.startValue = null;
124
+ } else {
125
+ let num = Number(val);
126
+ // 限制在 min 和 max 范围内
127
+ if (num < this.min) {
128
+ num = this.min;
129
+ } else if (num > this.max) {
130
+ num = this.max;
131
+ }
132
+ // 应用精度
133
+ this.startValue = this.formatPrecision(num);
134
+ }
135
+ this.emitValue();
136
+ },
137
+ // 处理结束值输入
138
+ handleEndInput(val) {
139
+ if (this.disabled) return;
140
+ if (val === "" || val === null || val === undefined) {
141
+ this.endValue = null;
142
+ } else {
143
+ let num = Number(val);
144
+ // 限制在 min 和 max 范围内
145
+ if (num < this.min) {
146
+ num = this.min;
147
+ } else if (num > this.max) {
148
+ num = this.max;
149
+ }
150
+ // 应用精度
151
+ this.endValue = this.formatPrecision(num);
152
+ }
153
+ this.emitValue();
154
+ },
155
+ // 处理起始值失焦
156
+ handleStartBlur() {
157
+ if (this.disabled) return;
158
+ // 只有当启用自动填充默认值,且只输入了起始值,结束值才默认为最大值
159
+ if (this.autoFillDefault && this.startValue !== null && this.endValue === null) {
160
+ this.endValue = this.formatPrecision(this.max);
161
+ }
162
+ // 应用精度
163
+ if (this.startValue !== null) {
164
+ this.startValue = this.formatPrecision(this.startValue);
165
+ }
166
+ // 验证范围
167
+ this.validateRange();
168
+ this.emitValue();
169
+ },
170
+ // 处理结束值失焦
171
+ handleEndBlur() {
172
+ if (this.disabled) return;
173
+ // 只有当启用自动填充默认值,且只输入了结束值,起始值才默认为最小值
174
+ if (this.autoFillDefault && this.endValue !== null && this.startValue === null) {
175
+ this.startValue = this.formatPrecision(this.min);
176
+ }
177
+ // 应用精度
178
+ if (this.endValue !== null) {
179
+ this.endValue = this.formatPrecision(this.endValue);
180
+ }
181
+ // 验证范围
182
+ this.validateRange();
183
+ this.emitValue();
184
+ },
185
+ // 验证范围
186
+ validateRange() {
187
+ if (this.startValue !== null && this.endValue !== null) {
188
+ // 确保起始值不大于结束值
189
+ if (this.startValue > this.endValue) {
190
+ // 如果起始值大于结束值,交换它们
191
+ const temp = this.startValue;
192
+ this.startValue = this.formatPrecision(this.endValue);
193
+ this.endValue = this.formatPrecision(temp);
194
+ }
195
+ }
196
+ },
197
+ // 清空
198
+ handleClear() {
199
+ if (this.disabled) return;
200
+ this.startValue = null;
201
+ this.endValue = null;
202
+ this.emitValue();
203
+ },
204
+ // 触发 v-model 更新
205
+ emitValue() {
206
+ const result = [this.startValue, this.endValue];
207
+ this.$emit("input", result);
208
+ this.$emit("change", result);
209
+ },
210
+ },
211
+ };
212
+ </script>
213
+
214
+ <style lang="scss" scoped>
215
+ .ol-number-range {
216
+ position: relative;
217
+ display: inline-flex;
218
+ align-items: center;
219
+ width: 100%;
220
+ background-color: #fff;
221
+ border: 1px solid #dcdfe6;
222
+ border-radius: 4px;
223
+ transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
224
+ padding: 0 30px 0 10px;
225
+ box-sizing: border-box;
226
+ height: 32px;
227
+ line-height: 32px;
228
+
229
+ &:hover {
230
+ border-color: #c0c4cc;
231
+ }
232
+
233
+ &:focus-within {
234
+ border-color: #409eff;
235
+ outline: none;
236
+ }
237
+
238
+ .range-input {
239
+ flex: 1;
240
+ border: none;
241
+ background: transparent;
242
+ padding: 0;
243
+ height: 100%;
244
+ line-height: inherit;
245
+
246
+ ::v-deep .el-input__inner {
247
+ border: none;
248
+ padding: 0;
249
+ height: 100%;
250
+ line-height: inherit;
251
+ background: transparent;
252
+ text-align: center;
253
+ font-size: 14px;
254
+ color: #606266;
255
+
256
+ &:focus {
257
+ border: none;
258
+ outline: none;
259
+ }
260
+
261
+ &::placeholder {
262
+ color: #c0c4cc;
263
+ }
264
+ }
265
+
266
+ ::v-deep .el-input__inner::-webkit-outer-spin-button,
267
+ ::v-deep .el-input__inner::-webkit-inner-spin-button {
268
+ -webkit-appearance: none;
269
+ margin: 0;
270
+ }
271
+
272
+ ::v-deep .el-input__inner[type="number"] {
273
+ -moz-appearance: textfield;
274
+ appearance: textfield;
275
+ }
276
+ }
277
+
278
+ .start-input {
279
+ ::v-deep .el-input__inner {
280
+ text-align: center;
281
+ }
282
+ }
283
+
284
+ .end-input {
285
+ ::v-deep .el-input__inner {
286
+ text-align: center;
287
+ }
288
+ }
289
+
290
+ .range-separator {
291
+ flex-shrink: 0;
292
+ padding: 0 8px;
293
+ color: #c0c4cc;
294
+ font-size: 14px;
295
+ line-height: 1;
296
+ }
297
+
298
+ .clear-icon {
299
+ position: absolute;
300
+ right: 8px;
301
+ top: 50%;
302
+ transform: translateY(-50%);
303
+ cursor: pointer;
304
+ color: #c0c4cc;
305
+ font-size: 14px;
306
+ transition: color 0.2s;
307
+ z-index: 1;
308
+
309
+ &:hover {
310
+ color: #909399;
311
+ }
312
+ }
313
+ }
314
+
315
+ // 小尺寸适配
316
+ ::v-deep .el-form-item--small .ol-number-range {
317
+ padding: 0 30px 0 10px;
318
+ height: 28px;
319
+ line-height: 28px;
320
+
321
+ .range-input {
322
+ height: 28px;
323
+ line-height: 28px;
324
+
325
+ ::v-deep .el-input__inner {
326
+ height: 28px;
327
+ line-height: 28px;
328
+ font-size: 13px;
329
+ }
330
+ }
331
+ }
332
+
333
+ // 禁用状态
334
+ .ol-number-range.is-disabled {
335
+ background-color: #f5f7fa;
336
+ border-color: #e4e7ed;
337
+ cursor: not-allowed;
338
+
339
+ .range-input {
340
+ ::v-deep .el-input__inner {
341
+ background-color: #f5f7fa;
342
+ color: #c0c4cc;
343
+ cursor: not-allowed;
344
+ }
345
+ }
346
+
347
+ .clear-icon {
348
+ display: none;
349
+ }
350
+ }
351
+ </style>