ol-base-components 1.5.1 → 1.5.3
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 +1 -1
- package/src/package/index.js +24 -77
- package/src/package/table/src/index.vue +35 -29
package/package.json
CHANGED
package/src/package/index.js
CHANGED
|
@@ -27,7 +27,6 @@ ${cyan}感谢使用我们的组件库,期待你的精彩应用!${reset}
|
|
|
27
27
|
const DB_NAME = "SwaggerDB";
|
|
28
28
|
const DB_VERSION = 1;
|
|
29
29
|
const STORE_NAME = "swaggerDataStore";
|
|
30
|
-
const LOGIN_STATUS_KEY = "isLoggedIn"; // 存储登录状态的键
|
|
31
30
|
|
|
32
31
|
// 打开数据库
|
|
33
32
|
function openDatabase() {
|
|
@@ -63,7 +62,7 @@ function storeData(data) {
|
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
// 获取数据
|
|
66
|
-
function getData() {
|
|
65
|
+
export function getData() {
|
|
67
66
|
return openDatabase().then((db) => {
|
|
68
67
|
return new Promise((resolve, reject) => {
|
|
69
68
|
const transaction = db.transaction(STORE_NAME, "readonly");
|
|
@@ -94,84 +93,39 @@ function clearData() {
|
|
|
94
93
|
});
|
|
95
94
|
}
|
|
96
95
|
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
Vue,
|
|
109
|
-
options = {
|
|
110
|
-
swaggerUrl: "",
|
|
111
|
-
successSwaggerCallback: null,
|
|
112
|
-
}
|
|
113
|
-
) => {
|
|
114
|
-
// 检查登录状态
|
|
115
|
-
const isLoggedIn = getLoginStatus();
|
|
116
|
-
|
|
117
|
-
// 如果 $swagger 已经存在,直接返回
|
|
118
|
-
if (Vue.prototype.$swagger) {
|
|
119
|
-
if (
|
|
120
|
-
options.successSwaggerCallback &&
|
|
121
|
-
typeof options.successSwaggerCallback === "function"
|
|
122
|
-
) {
|
|
123
|
-
options.successSwaggerCallback();
|
|
124
|
-
}
|
|
125
|
-
return; // 数据已加载,直接返回
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (options && options.swaggerUrl) {
|
|
129
|
-
// 检查 IndexedDB 中是否存在 Swagger 数据
|
|
130
|
-
if (isLoggedIn) {
|
|
131
|
-
try {
|
|
132
|
-
const cachedData = await getData();
|
|
133
|
-
if (cachedData) {
|
|
134
|
-
Vue.prototype.$swagger = { specification: cachedData };
|
|
135
|
-
if (
|
|
136
|
-
options.successSwaggerCallback &&
|
|
137
|
-
typeof options.successSwaggerCallback === "function"
|
|
138
|
-
) {
|
|
139
|
-
options.successSwaggerCallback();
|
|
140
|
-
}
|
|
141
|
-
return; // 数据已加载,直接返回
|
|
142
|
-
}
|
|
143
|
-
} catch (error) {
|
|
144
|
-
console.error("获取缓存数据失败:", error);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// 用户未登录或缓存数据不存在,重新请求 Swagger 数据
|
|
96
|
+
// 注册
|
|
97
|
+
const swaggerInstall = async (swaggerUrl) => {
|
|
98
|
+
if (!swaggerUrl) return Promise.reject(new Error("Swagger URL is required.")); // 检查 Swagger URL
|
|
99
|
+
|
|
100
|
+
// 尝试从 IndexedDB 获取 Swagger 数据
|
|
101
|
+
const cachedData = await getData();
|
|
102
|
+
if (cachedData) {
|
|
103
|
+
consoleTooltip();
|
|
104
|
+
return Promise.resolve(cachedData); // 返回已解析的 Promise
|
|
105
|
+
} else {
|
|
106
|
+
// 如果没有缓存数据,重新请求 Swagger 数据
|
|
149
107
|
try {
|
|
150
108
|
showLoading();
|
|
151
|
-
const client = await SwaggerClient(
|
|
109
|
+
const client = await SwaggerClient(swaggerUrl);
|
|
152
110
|
const swaggerData = client.spec; // 获取 Swagger 数据
|
|
153
111
|
await storeData(swaggerData); // 缓存数据到 IndexedDB
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
options.successSwaggerCallback &&
|
|
158
|
-
typeof options.successSwaggerCallback === "function"
|
|
159
|
-
) {
|
|
160
|
-
options.successSwaggerCallback();
|
|
161
|
-
hideLoading();
|
|
162
|
-
}
|
|
112
|
+
hideLoading();
|
|
113
|
+
consoleTooltip();
|
|
114
|
+
return Promise.resolve(swaggerData); // 返回已解析的 Promise
|
|
163
115
|
} catch (error) {
|
|
116
|
+
hideLoading();
|
|
164
117
|
console.error("获取 Swagger 数据失败:", error);
|
|
118
|
+
return Promise.reject(error); // 返回拒绝的 Promise
|
|
165
119
|
}
|
|
166
120
|
}
|
|
167
|
-
|
|
121
|
+
};
|
|
122
|
+
// 销毁
|
|
123
|
+
const swaggerUnload = async function () {
|
|
124
|
+
await clearData(); // 清空 IndexedDB 中的缓存数据
|
|
168
125
|
};
|
|
169
126
|
|
|
170
127
|
const components = [OlTable, OlSearch, Dialog];
|
|
171
128
|
|
|
172
|
-
const SWAGGER_DATA_KEY = "swaggerData"; // 存储 Swagger 数据的键
|
|
173
|
-
let isLoggedIn = false; // 用于跟踪用户登录状态
|
|
174
|
-
|
|
175
129
|
// 自定义加载指示器
|
|
176
130
|
function showLoading() {
|
|
177
131
|
// 创建样式
|
|
@@ -241,18 +195,11 @@ const install = async function (
|
|
|
241
195
|
components.map((item) => {
|
|
242
196
|
Vue.component(`ol-${item.name}`, item);
|
|
243
197
|
});
|
|
244
|
-
swaggerInstall(Vue, options);
|
|
198
|
+
await swaggerInstall(Vue, options);
|
|
245
199
|
consoleTooltip();
|
|
246
200
|
};
|
|
247
201
|
|
|
248
|
-
// 提供一个方法用于用户退出登录时调用
|
|
249
|
-
export const OlLogout = async function () {
|
|
250
|
-
// 重置登录状态
|
|
251
|
-
storeLoginStatus(false); // 清除 localStorage 中的登录状态
|
|
252
|
-
await clearData(); // 清空 IndexedDB 中的缓存数据
|
|
253
|
-
Vue.prototype.$swagger = null; // 清空 Swagger 数据
|
|
254
|
-
};
|
|
255
|
-
|
|
256
202
|
// 判断是否引入文件
|
|
257
203
|
export default install; //全局导入
|
|
258
204
|
export { OlTable, OlSearch, Dialog }; //按需导入
|
|
205
|
+
export { swaggerInstall, swaggerUnload };
|
|
@@ -235,6 +235,7 @@
|
|
|
235
235
|
<script>
|
|
236
236
|
import printTemplate from "./printTable.vue";
|
|
237
237
|
import nodata from "./nodata.jpg";
|
|
238
|
+
import { getData } from '../../index.js'
|
|
238
239
|
export default {
|
|
239
240
|
name: "table",
|
|
240
241
|
components: {
|
|
@@ -403,37 +404,42 @@ export default {
|
|
|
403
404
|
},
|
|
404
405
|
methods: {
|
|
405
406
|
init() {
|
|
406
|
-
|
|
407
|
+
// 从 IndexedDB 中获取 Swagger 数据
|
|
408
|
+
getData().then((swaggerData) => {
|
|
409
|
+
const swaggerColumns = swaggerData.paths[this.url].get.responses["200"].content['application/json'].schema.properties.items.items.properties;
|
|
407
410
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
})
|
|
423
|
-
|
|
424
|
-
// 一定加上selection,通过show显示隐藏
|
|
425
|
-
const itemSelection = this.tableData.columns.find((item) => item.type == "selection");
|
|
426
|
-
const hasSelection = this.tableData.options.selection;
|
|
427
|
-
if (itemSelection) {
|
|
428
|
-
itemSelection.show = !!hasSelection;
|
|
429
|
-
} else {
|
|
430
|
-
this.tableData.columns.unshift({
|
|
431
|
-
label: "",
|
|
432
|
-
minWidth: "",
|
|
433
|
-
type: "selection",
|
|
434
|
-
show: !!hasSelection,
|
|
411
|
+
Object.keys(swaggerColumns).forEach(key => {
|
|
412
|
+
const item = swaggerColumns[key];
|
|
413
|
+
let tempItem = this.tableData.columns.find((e) => e.prop == key);
|
|
414
|
+
if (tempItem) {
|
|
415
|
+
tempItem = { ...item, ...tempItem };
|
|
416
|
+
} else if (item.description) {
|
|
417
|
+
this.tableData.columns.push({
|
|
418
|
+
prop: key,
|
|
419
|
+
label: item.description,
|
|
420
|
+
show: true,
|
|
421
|
+
sortable: false,
|
|
422
|
+
attrs: {}
|
|
423
|
+
});
|
|
424
|
+
}
|
|
435
425
|
});
|
|
436
|
-
|
|
426
|
+
|
|
427
|
+
// 一定加上selection,通过show显示隐藏
|
|
428
|
+
const itemSelection = this.tableData.columns.find((item) => item.type == "selection");
|
|
429
|
+
const hasSelection = this.tableData.options.selection;
|
|
430
|
+
if (itemSelection) {
|
|
431
|
+
itemSelection.show = !!hasSelection;
|
|
432
|
+
} else {
|
|
433
|
+
this.tableData.columns.unshift({
|
|
434
|
+
label: "",
|
|
435
|
+
minWidth: "",
|
|
436
|
+
type: "selection",
|
|
437
|
+
show: !!hasSelection,
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
}).catch((error) => {
|
|
441
|
+
console.error("获取 Swagger 数据失败:", error);
|
|
442
|
+
});
|
|
437
443
|
},
|
|
438
444
|
radioChange() {
|
|
439
445
|
this.$emit("radioChange", this.twinPage);
|