ol-base-components 1.5.1 → 1.5.2
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 +28 -59
- package/src/package/table/src/index.vue +35 -29
package/package.json
CHANGED
package/src/package/index.js
CHANGED
|
@@ -63,7 +63,7 @@ function storeData(data) {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
// 获取数据
|
|
66
|
-
function getData() {
|
|
66
|
+
export function getData() {
|
|
67
67
|
return openDatabase().then((db) => {
|
|
68
68
|
return new Promise((resolve, reject) => {
|
|
69
69
|
const transaction = db.transaction(STORE_NAME, "readonly");
|
|
@@ -104,74 +104,50 @@ function getLoginStatus() {
|
|
|
104
104
|
return localStorage.getItem(LOGIN_STATUS_KEY) === "true";
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
swaggerUrl: "",
|
|
111
|
-
successSwaggerCallback: null,
|
|
112
|
-
}
|
|
113
|
-
) => {
|
|
107
|
+
// 注册
|
|
108
|
+
const swaggerInstall = async (swaggerUrl) => {
|
|
109
|
+
if (!swaggerUrl) return Promise.reject();
|
|
114
110
|
// 检查登录状态
|
|
115
111
|
const isLoggedIn = getLoginStatus();
|
|
116
112
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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);
|
|
113
|
+
if (isLoggedIn) {
|
|
114
|
+
try {
|
|
115
|
+
const cachedData = await getData();
|
|
116
|
+
if (cachedData) {
|
|
117
|
+
consoleTooltip();
|
|
118
|
+
return Promise.resolve(cachedData);
|
|
145
119
|
}
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error("获取缓存数据失败:", error);
|
|
146
122
|
}
|
|
147
|
-
|
|
123
|
+
} else {
|
|
148
124
|
// 用户未登录或缓存数据不存在,重新请求 Swagger 数据
|
|
149
125
|
try {
|
|
150
126
|
showLoading();
|
|
151
|
-
const client = await SwaggerClient(
|
|
127
|
+
const client = await SwaggerClient(swaggerUrl);
|
|
152
128
|
const swaggerData = client.spec; // 获取 Swagger 数据
|
|
153
129
|
await storeData(swaggerData); // 缓存数据到 IndexedDB
|
|
154
|
-
Vue.prototype.$swagger = { specification: swaggerData };
|
|
155
130
|
storeLoginStatus(true); // 设置用户为已登录状态
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
) {
|
|
160
|
-
options.successSwaggerCallback();
|
|
161
|
-
hideLoading();
|
|
162
|
-
}
|
|
131
|
+
hideLoading();
|
|
132
|
+
consoleTooltip();
|
|
133
|
+
return Promise.resolve(swaggerData); // 返回已解析的 Promise
|
|
163
134
|
} catch (error) {
|
|
135
|
+
hideLoading();
|
|
164
136
|
console.error("获取 Swagger 数据失败:", error);
|
|
137
|
+
return Promise.reject(error); // 返回拒绝的 Promise
|
|
165
138
|
}
|
|
166
139
|
}
|
|
167
|
-
|
|
140
|
+
return Promise.reject(new Error("Swagger URL is required.")); // 返回拒绝的 Promise
|
|
141
|
+
};
|
|
142
|
+
// 销毁
|
|
143
|
+
const swaggerUnload = async function () {
|
|
144
|
+
// 重置登录状态
|
|
145
|
+
storeLoginStatus(false); // 清除 localStorage 中的登录状态
|
|
146
|
+
await clearData(); // 清空 IndexedDB 中的缓存数据
|
|
168
147
|
};
|
|
169
148
|
|
|
170
149
|
const components = [OlTable, OlSearch, Dialog];
|
|
171
150
|
|
|
172
|
-
const SWAGGER_DATA_KEY = "swaggerData"; // 存储 Swagger 数据的键
|
|
173
|
-
let isLoggedIn = false; // 用于跟踪用户登录状态
|
|
174
|
-
|
|
175
151
|
// 自定义加载指示器
|
|
176
152
|
function showLoading() {
|
|
177
153
|
// 创建样式
|
|
@@ -241,18 +217,11 @@ const install = async function (
|
|
|
241
217
|
components.map((item) => {
|
|
242
218
|
Vue.component(`ol-${item.name}`, item);
|
|
243
219
|
});
|
|
244
|
-
swaggerInstall(Vue, options);
|
|
220
|
+
await swaggerInstall(Vue, options);
|
|
245
221
|
consoleTooltip();
|
|
246
222
|
};
|
|
247
223
|
|
|
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
224
|
// 判断是否引入文件
|
|
257
225
|
export default install; //全局导入
|
|
258
226
|
export { OlTable, OlSearch, Dialog }; //按需导入
|
|
227
|
+
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);
|