ol-base-components 1.5.0 → 1.5.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/package.json +1 -1
- package/src/package/index.js +62 -57
package/package.json
CHANGED
package/src/package/index.js
CHANGED
|
@@ -104,10 +104,67 @@ function getLoginStatus() {
|
|
|
104
104
|
return localStorage.getItem(LOGIN_STATUS_KEY) === "true";
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
export const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
export const swaggerInstall = async (
|
|
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 数据
|
|
149
|
+
try {
|
|
150
|
+
showLoading();
|
|
151
|
+
const client = await SwaggerClient(options.swaggerUrl);
|
|
152
|
+
const swaggerData = client.spec; // 获取 Swagger 数据
|
|
153
|
+
await storeData(swaggerData); // 缓存数据到 IndexedDB
|
|
154
|
+
Vue.prototype.$swagger = { specification: swaggerData };
|
|
155
|
+
storeLoginStatus(true); // 设置用户为已登录状态
|
|
156
|
+
if (
|
|
157
|
+
options.successSwaggerCallback &&
|
|
158
|
+
typeof options.successSwaggerCallback === "function"
|
|
159
|
+
) {
|
|
160
|
+
options.successSwaggerCallback();
|
|
161
|
+
hideLoading();
|
|
162
|
+
}
|
|
163
|
+
} catch (error) {
|
|
164
|
+
console.error("获取 Swagger 数据失败:", error);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
consoleTooltip();
|
|
111
168
|
};
|
|
112
169
|
|
|
113
170
|
const components = [OlTable, OlSearch, Dialog];
|
|
@@ -184,59 +241,7 @@ const install = async function (
|
|
|
184
241
|
components.map((item) => {
|
|
185
242
|
Vue.component(`ol-${item.name}`, item);
|
|
186
243
|
});
|
|
187
|
-
|
|
188
|
-
const isLoggedIn = getLoginStatus();
|
|
189
|
-
|
|
190
|
-
// 如果 $swagger 已经存在,直接返回
|
|
191
|
-
if (Vue.prototype.$swagger) {
|
|
192
|
-
if (
|
|
193
|
-
options.successSwaggerCallback &&
|
|
194
|
-
typeof options.successSwaggerCallback === "function"
|
|
195
|
-
) {
|
|
196
|
-
options.successSwaggerCallback();
|
|
197
|
-
}
|
|
198
|
-
return; // 数据已加载,直接返回
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (options && options.swaggerUrl) {
|
|
202
|
-
// 检查 IndexedDB 中是否存在 Swagger 数据
|
|
203
|
-
if (isLoggedIn) {
|
|
204
|
-
try {
|
|
205
|
-
const cachedData = await getData();
|
|
206
|
-
if (cachedData) {
|
|
207
|
-
Vue.prototype.$swagger = { specification: cachedData };
|
|
208
|
-
if (
|
|
209
|
-
options.successSwaggerCallback &&
|
|
210
|
-
typeof options.successSwaggerCallback === "function"
|
|
211
|
-
) {
|
|
212
|
-
options.successSwaggerCallback();
|
|
213
|
-
}
|
|
214
|
-
return; // 数据已加载,直接返回
|
|
215
|
-
}
|
|
216
|
-
} catch (error) {
|
|
217
|
-
console.error("获取缓存数据失败:", error);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// 用户未登录或缓存数据不存在,重新请求 Swagger 数据
|
|
222
|
-
try {
|
|
223
|
-
showLoading();
|
|
224
|
-
const client = await SwaggerClient(options.swaggerUrl);
|
|
225
|
-
const swaggerData = client.spec; // 获取 Swagger 数据
|
|
226
|
-
await storeData(swaggerData); // 缓存数据到 IndexedDB
|
|
227
|
-
Vue.prototype.$swagger = { specification: swaggerData };
|
|
228
|
-
storeLoginStatus(true); // 设置用户为已登录状态
|
|
229
|
-
if (
|
|
230
|
-
options.successSwaggerCallback &&
|
|
231
|
-
typeof options.successSwaggerCallback === "function"
|
|
232
|
-
) {
|
|
233
|
-
options.successSwaggerCallback();
|
|
234
|
-
hideLoading();
|
|
235
|
-
}
|
|
236
|
-
} catch (error) {
|
|
237
|
-
console.error("获取 Swagger 数据失败:", error);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
244
|
+
swaggerInstall(Vue, options);
|
|
240
245
|
consoleTooltip();
|
|
241
246
|
};
|
|
242
247
|
|