ol-base-components 1.4.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/README.md +26 -1
- package/package.json +1 -1
- package/src/package/index.js +82 -18
package/README.md
CHANGED
|
@@ -19,8 +19,10 @@ npm install ol-base-components
|
|
|
19
19
|
|
|
20
20
|
## 使用说明
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
- **基本用法**:通用常规组件,ol-table ol-search ol-dialogTemplate
|
|
23
|
+
- **带 Swagger 支持的用法**:适用于需要从 Swagger API 获取数据的场景。通过传入 `swaggerUrl` 和 `successSwaggerCallback`,可以在成功获取 Swagger 数据后初始化 Vue 实例。
|
|
23
24
|
|
|
25
|
+
### 1. 基本用法
|
|
24
26
|
```javascript
|
|
25
27
|
// main.js
|
|
26
28
|
import Vue from "vue";
|
|
@@ -35,6 +37,29 @@ new Vue({
|
|
|
35
37
|
}).$mount("#app");
|
|
36
38
|
```
|
|
37
39
|
|
|
40
|
+
### 2. 带 Swagger 支持的用法
|
|
41
|
+
```javascript
|
|
42
|
+
// main.js
|
|
43
|
+
import Vue from "vue";
|
|
44
|
+
import App from "./App.vue";
|
|
45
|
+
import OlBaseComponents from "ol-base-components"; // 导入组件库
|
|
46
|
+
|
|
47
|
+
// 使用组件库
|
|
48
|
+
Vue.use(OlBaseComponents, {
|
|
49
|
+
swaggerUrl: "http://192.168.xxx.xxx:20019/swagger/v1/swagger.json",
|
|
50
|
+
successSwaggerCallback: () => {
|
|
51
|
+
new Vue({
|
|
52
|
+
el: "#app",
|
|
53
|
+
router,
|
|
54
|
+
store,
|
|
55
|
+
i18n,
|
|
56
|
+
render: h => h(App)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
|
|
38
63
|
## 组件示例
|
|
39
64
|
|
|
40
65
|
### 搜索框组件
|
package/package.json
CHANGED
package/src/package/index.js
CHANGED
|
@@ -104,29 +104,13 @@ function getLoginStatus() {
|
|
|
104
104
|
return localStorage.getItem(LOGIN_STATUS_KEY) === "true";
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
export const
|
|
108
|
-
const client = await new SwaggerClient(swaggerUrl);
|
|
109
|
-
console.log("client", client);
|
|
110
|
-
Vue.prototype.$swagger = { specification: client.spec };
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const components = [OlTable, OlSearch, Dialog];
|
|
114
|
-
|
|
115
|
-
const SWAGGER_DATA_KEY = "swaggerData"; // 存储 Swagger 数据的键
|
|
116
|
-
let isLoggedIn = false; // 用于跟踪用户登录状态
|
|
117
|
-
|
|
118
|
-
const install = async function (
|
|
107
|
+
export const swaggerInstall = async (
|
|
119
108
|
Vue,
|
|
120
109
|
options = {
|
|
121
110
|
swaggerUrl: "",
|
|
122
111
|
successSwaggerCallback: null,
|
|
123
112
|
}
|
|
124
|
-
) {
|
|
125
|
-
// 遍历所有组件
|
|
126
|
-
components.map((item) => {
|
|
127
|
-
Vue.component(`ol-${item.name}`, item);
|
|
128
|
-
});
|
|
129
|
-
|
|
113
|
+
) => {
|
|
130
114
|
// 检查登录状态
|
|
131
115
|
const isLoggedIn = getLoginStatus();
|
|
132
116
|
|
|
@@ -163,6 +147,7 @@ const install = async function (
|
|
|
163
147
|
|
|
164
148
|
// 用户未登录或缓存数据不存在,重新请求 Swagger 数据
|
|
165
149
|
try {
|
|
150
|
+
showLoading();
|
|
166
151
|
const client = await SwaggerClient(options.swaggerUrl);
|
|
167
152
|
const swaggerData = client.spec; // 获取 Swagger 数据
|
|
168
153
|
await storeData(swaggerData); // 缓存数据到 IndexedDB
|
|
@@ -173,6 +158,7 @@ const install = async function (
|
|
|
173
158
|
typeof options.successSwaggerCallback === "function"
|
|
174
159
|
) {
|
|
175
160
|
options.successSwaggerCallback();
|
|
161
|
+
hideLoading();
|
|
176
162
|
}
|
|
177
163
|
} catch (error) {
|
|
178
164
|
console.error("获取 Swagger 数据失败:", error);
|
|
@@ -181,6 +167,84 @@ const install = async function (
|
|
|
181
167
|
consoleTooltip();
|
|
182
168
|
};
|
|
183
169
|
|
|
170
|
+
const components = [OlTable, OlSearch, Dialog];
|
|
171
|
+
|
|
172
|
+
const SWAGGER_DATA_KEY = "swaggerData"; // 存储 Swagger 数据的键
|
|
173
|
+
let isLoggedIn = false; // 用于跟踪用户登录状态
|
|
174
|
+
|
|
175
|
+
// 自定义加载指示器
|
|
176
|
+
function showLoading() {
|
|
177
|
+
// 创建样式
|
|
178
|
+
const style = document.createElement("style");
|
|
179
|
+
style.innerHTML = `
|
|
180
|
+
@keyframes spin {
|
|
181
|
+
0% { transform: rotate(0deg); }
|
|
182
|
+
100% { transform: rotate(360deg); }
|
|
183
|
+
}
|
|
184
|
+
#loading-spinner {
|
|
185
|
+
width: 50px; /* 调整大小 */
|
|
186
|
+
height: 50px; /* 调整大小 */
|
|
187
|
+
border: 8px solid rgba(255, 255, 255, 0.3);
|
|
188
|
+
border-top: 8px solid #a8c8e0; /* 与背景色协调的颜色 */
|
|
189
|
+
border-radius: 50%;
|
|
190
|
+
animation: spin 1s linear infinite; /* 添加旋转动画 */
|
|
191
|
+
margin-bottom: 10px; /* 图标和文本之间的间距 */
|
|
192
|
+
}
|
|
193
|
+
#loading {
|
|
194
|
+
background: linear-gradient(135deg, #a8c8e0, #f0f4f8); /* 更柔和的渐变背景 */
|
|
195
|
+
color: #333; /* 文本颜色 */
|
|
196
|
+
}
|
|
197
|
+
`;
|
|
198
|
+
document.head.appendChild(style);
|
|
199
|
+
|
|
200
|
+
// 创建加载指示器
|
|
201
|
+
const loadingDiv = document.createElement("div");
|
|
202
|
+
loadingDiv.id = "loading";
|
|
203
|
+
loadingDiv.style.position = "fixed";
|
|
204
|
+
loadingDiv.style.top = "0";
|
|
205
|
+
loadingDiv.style.left = "0";
|
|
206
|
+
loadingDiv.style.width = "100%";
|
|
207
|
+
loadingDiv.style.height = "100%";
|
|
208
|
+
loadingDiv.style.display = "flex"; // 使用 flexbox
|
|
209
|
+
loadingDiv.style.flexDirection = "column"; // 设置为上下排列
|
|
210
|
+
loadingDiv.style.justifyContent = "center"; // 垂直居中
|
|
211
|
+
loadingDiv.style.alignItems = "center"; // 水平居中
|
|
212
|
+
|
|
213
|
+
// 创建旋转的加载图标
|
|
214
|
+
const spinner = document.createElement("div");
|
|
215
|
+
spinner.id = "loading-spinner";
|
|
216
|
+
loadingDiv.appendChild(spinner);
|
|
217
|
+
|
|
218
|
+
// 添加文本
|
|
219
|
+
const loadingText = document.createElement("div");
|
|
220
|
+
loadingText.innerText = "初始化数据中,请耐心等待...";
|
|
221
|
+
loadingDiv.appendChild(loadingText);
|
|
222
|
+
|
|
223
|
+
document.body.appendChild(loadingDiv);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function hideLoading() {
|
|
227
|
+
const loadingDiv = document.getElementById("loading");
|
|
228
|
+
if (loadingDiv) {
|
|
229
|
+
document.body.removeChild(loadingDiv);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const install = async function (
|
|
234
|
+
Vue,
|
|
235
|
+
options = {
|
|
236
|
+
swaggerUrl: "",
|
|
237
|
+
successSwaggerCallback: null,
|
|
238
|
+
}
|
|
239
|
+
) {
|
|
240
|
+
// 遍历所有组件
|
|
241
|
+
components.map((item) => {
|
|
242
|
+
Vue.component(`ol-${item.name}`, item);
|
|
243
|
+
});
|
|
244
|
+
swaggerInstall(Vue, options);
|
|
245
|
+
consoleTooltip();
|
|
246
|
+
};
|
|
247
|
+
|
|
184
248
|
// 提供一个方法用于用户退出登录时调用
|
|
185
249
|
export const OlLogout = async function () {
|
|
186
250
|
// 重置登录状态
|