uni-oaview 1.9.0 → 1.9.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/README.md CHANGED
@@ -54,6 +54,33 @@ app.use(OaView, {
54
54
  });
55
55
  ```
56
56
 
57
+ 当前配置定义位于 `src/configs/oa-view-config.ts`,用于统一维护:
58
+
59
+ - `OaViewOptions` - 插件配置项类型定义
60
+ - `OaViewConfig` - 运行时配置对象类型定义
61
+ - `defaultWhiteUrls` - 默认白名单地址列表
62
+ - `OA_VIEW_CONFIG_KEY` - `oa-page` 读取运行时配置时使用的注入 key
63
+
64
+ ### 配置生效机制
65
+
66
+ `whiteUrls` 的生效链路如下:
67
+
68
+ 1. 业务项目在 `main.ts` 中通过 `app.use(OaView, options)` 安装插件
69
+ 2. 插件在 `install()` 中通过 `app.provide()` 注入运行时配置
70
+ 3. `oa-page` 组件通过 `inject()` 读取配置
71
+ 4. 当 `baseUrl` 命中白名单,或者本地 `isDebug` 为 `true` 时,自动展示 `oa-vconsole`
72
+
73
+ 如果你发现配置没有生效,请优先检查以下几项:
74
+
75
+ 1. 是否已在业务项目入口文件中执行 `app.use(OaView, { whiteUrls: [...] })`
76
+ 2. 页面是否使用了 `oa-page` 组件包裹
77
+ 3. `baseUrl` 是否已正确写入本地存储
78
+ 4. 白名单地址是否与 `baseUrl` 的协议、域名、端口保持一致
79
+
80
+ ### whiteUrls 完整教程
81
+
82
+ `whiteUrls` 用于控制 `oa-vconsole` 在哪些业务地址下自动显示,适用于开发联调、测试环境排障和定向灰度调试。
83
+
57
84
  ### whiteUrls
58
85
 
59
86
  配置 vconsole 调试工具自动显示的白名单 URL。
@@ -68,6 +95,82 @@ app.use(OaView, {
68
95
 
69
96
  **说明**: 当应用运行在白名单内的 URL 时,`oa-page` 组件会自动显示 vconsole 调试工具。传入空数组 `[]` 可禁用自动显示。
70
97
 
98
+ #### 步骤 1:在入口文件安装插件
99
+
100
+ ```ts
101
+ import { createSSRApp } from 'vue';
102
+ import App from './App.vue';
103
+ import OaView from 'getui-oa-oaview-sdk-uniapp';
104
+
105
+ export function createApp() {
106
+ const app = createSSRApp(App);
107
+
108
+ app.use(OaView, {
109
+ whiteUrls: ['http://192.168.18.136:31080', 'http://192.168.104.127'],
110
+ });
111
+
112
+ return { app };
113
+ }
114
+ ```
115
+
116
+ #### 步骤 2:确保页面使用 `oa-page`
117
+
118
+ ```vue
119
+ <template>
120
+ <oa-page>
121
+ <view>页面内容</view>
122
+ </oa-page>
123
+ </template>
124
+ ```
125
+
126
+ 如果页面没有包裹 `oa-page`,即使已经安装插件,白名单配置也不会触发 `oa-vconsole` 的展示逻辑。
127
+
128
+ #### 步骤 3:确认 `baseUrl` 已初始化
129
+
130
+ `oa-page` 会根据本地存储中的 `baseUrl` 与 `whiteUrls` 做匹配,因此需要在应用启动阶段先正确写入:
131
+
132
+ ```ts
133
+ uni.setStorageSync('baseUrl', 'http://192.168.18.136:31080');
134
+ ```
135
+
136
+ #### 步骤 4:检查匹配结果
137
+
138
+ 建议优先保证以下内容一致:
139
+
140
+ - 协议一致,例如都为 `http://` 或都为 `https://`
141
+ - 域名或 IP 一致
142
+ - 端口一致
143
+ - 尽量不要混用带尾斜杠和不带尾斜杠的写法
144
+
145
+ 推荐写法:
146
+
147
+ ```ts
148
+ whiteUrls: ['http://192.168.18.136:31080', 'http://192.168.104.127'];
149
+ ```
150
+
151
+ #### 常见问题
152
+
153
+ **1. 已传入 `whiteUrls`,但 `oa-page` 里还是默认值**
154
+
155
+ 通常是以下原因之一:
156
+
157
+ - 插件未在业务入口安装
158
+ - 页面未使用 `oa-page`
159
+ - 当前联调方式没有正确加载最新包内容
160
+
161
+ **2. `whiteUrls` 已正确注入,但 `showLog` 仍然是 `false`**
162
+
163
+ 通常需要继续检查:
164
+
165
+ - `baseUrl` 是否为空
166
+ - `baseUrl` 是否是目标业务地址,而不是其他临时字符串
167
+ - `isDebug` 是否为 `false`
168
+
169
+ **3. 什么时候应该使用 `whiteUrls`,什么时候使用 `isDebug`**
170
+
171
+ - `whiteUrls` 适合固定地址环境自动开启调试
172
+ - `isDebug` 适合手动强制开启调试
173
+
71
174
  更多配置详情请参考 [SDK 配置文档](../../docs/zh/sdk-configuration.md)。
72
175
 
73
176
  ---
@@ -12,18 +12,10 @@
12
12
  import OaVconsole from '../oa-vconsole/oa-vconsole.vue';
13
13
  import NetworkError from './nextwork-error.vue';
14
14
  import GlobalComponents from './global-components.vue';
15
- import { OA_VIEW_CONFIG_KEY } from '../../src/index';
15
+ import { defaultWhiteUrls, OA_VIEW_CONFIG_KEY } from '../../src/configs/oa-view-config';
16
16
 
17
17
  const globalComponentsRef = ref<InstanceType<typeof GlobalComponents>>();
18
18
 
19
- // 默认白名单(兜底值)
20
- const defaultWhiteUrls = [
21
- 'http://192.168.11.231:6174',
22
- 'http://192.168.10.11:6174',
23
- 'http://dev-oa.ge.cn:6174',
24
- 'http://test-oa.ge.cn:6174',
25
- ];
26
-
27
19
  // 注入配置,未配置时使用默认
28
20
  const config = inject(OA_VIEW_CONFIG_KEY, { whiteUrls: defaultWhiteUrls });
29
21
  const whiteUrls = config.whiteUrls;
@@ -33,7 +25,7 @@
33
25
  const windowHeight = uni.getSystemInfoSync()?.windowHeight ?? 'auto';
34
26
  const baseUrl = uni.getStorageSync('baseUrl');
35
27
  /** 如果在debug状态,或者是在白名单里面,则展示vconsole */
36
- const showLog = ref(whiteUrls.some((url) => url.includes(baseUrl)) || !!uni.getStorageSync('isDebug'));
28
+ const showLog = ref(whiteUrls.some((url) => baseUrl?.includes(url)) || !!uni.getStorageSync('isDebug'));
37
29
  let isLock = false;
38
30
  setTimeout(function () {
39
31
  isLock = true;
@@ -87,7 +87,7 @@
87
87
  failed: boolean;
88
88
  }
89
89
 
90
- const MAX_NETWORK_LOGS = 100;
90
+ const MAX_NETWORK_LOGS = 1000;
91
91
 
92
92
  const collapseRef = ref<{ resize?: () => void } | null>(null);
93
93
  // uni-collapse 的 v-model 在不同模式下可能是 string 或 string[]
package/dist/index.d.ts CHANGED
@@ -319,18 +319,42 @@ declare function useCookieTempFileUrl(url: string): {
319
319
  tempUrl: _mp_rt1_vue___Ref<string>;
320
320
  };
321
321
 
322
+ /**
323
+ * OA 页面插件配置项。
324
+ */
322
325
  interface OaViewOptions {
326
+ /**
327
+ * 允许展示调试能力的白名单地址列表。
328
+ */
323
329
  whiteUrls?: string[];
324
330
  }
325
- declare const OA_VIEW_CONFIG_KEY: unique symbol;
331
+ /**
332
+ * OA 页面运行时配置对象。
333
+ */
334
+ interface OaViewConfig {
335
+ /**
336
+ * 当前生效的白名单地址列表。
337
+ */
338
+ whiteUrls: string[];
339
+ }
340
+ /**
341
+ * 默认白名单地址列表。
342
+ */
343
+ declare const defaultWhiteUrls: string[];
344
+ /**
345
+ * OA 页面运行时配置注入 key。
346
+ * 使用字符串常量是为了兼容 dist 与源码组件并存时的 provide/inject 匹配。
347
+ */
348
+ declare const OA_VIEW_CONFIG_KEY: "oa-view-config";
349
+
326
350
  declare const plugin: Plugin;
327
351
  /**
328
- * 向客户端获取数据
329
- * @param eventName 事件名称
330
- * @param params 客户端传递事件的参数
331
- * @param immediate 是否立即返回
332
- * @returns
352
+ * 根据原生事件名称向客户端请求数据。
353
+ * @param eventName 原生事件名称。
354
+ * @param params 发送给客户端的参数对象。
355
+ * @param immediate 是否启用超时保护。
356
+ * @returns 返回客户端回传的数据结果。
333
357
  */
334
358
  declare function getDataByApp(eventName: string, params: Record<string, any>, immediate?: boolean): Promise<any>;
335
359
 
336
- export { CreateModalReturn, Message, MessageBox, ModalBaseEvents, ModalCloseReason, ModalHeaderEvents, ModalHeaderOptions, ModalOptions, OA_VIEW_CONFIG_KEY, OaViewOptions, RouteMethodName, VersionCheckRuntimeOptions, VersionCheckRuntimeState, VersionCheckSource, VersionCheckTriggerContext, closeAllModals, compareVersions, createDebounceFn, createModal, createVersionCheckRuntime, plugin as default, getAppVersion, getDataByApp, getTempFilePathForCookie, isCurrentVersionHigher, sendLaunchAppParamsLog, useCookieTempFileUrl, versionCheckRuntime };
360
+ export { CreateModalReturn, Message, MessageBox, ModalBaseEvents, ModalCloseReason, ModalHeaderEvents, ModalHeaderOptions, ModalOptions, OA_VIEW_CONFIG_KEY, OaViewConfig, OaViewOptions, RouteMethodName, VersionCheckRuntimeOptions, VersionCheckRuntimeState, VersionCheckSource, VersionCheckTriggerContext, closeAllModals, compareVersions, createDebounceFn, createModal, createVersionCheckRuntime, plugin as default, defaultWhiteUrls, getAppVersion, getDataByApp, getTempFilePathForCookie, isCurrentVersionHigher, sendLaunchAppParamsLog, useCookieTempFileUrl, versionCheckRuntime };
package/dist/index.esm.js CHANGED
@@ -509,7 +509,7 @@ function _toPropertyKey(arg) {
509
509
  */
510
510
  function sendLaunchAppParamsLog(params) {
511
511
  var _a;
512
- console.log('小程序启动入参:', params);
512
+ console.log('【OA View】小程序启动入参:', params);
513
513
  // #ifndef H5
514
514
  try {
515
515
  var outputData = JSON.parse(JSON.stringify((_a = params === null || params === void 0 ? void 0 : params.referrerInfo) === null || _a === void 0 ? void 0 : _a.extraData));
@@ -1071,6 +1071,16 @@ function createVersionCheckRuntime() {
1071
1071
  /** 默认版本检测运行时单例 */
1072
1072
  var versionCheckRuntime = createVersionCheckRuntime();
1073
1073
 
1074
+ /**
1075
+ * 默认白名单地址列表。
1076
+ */
1077
+ var defaultWhiteUrls = ['http://192.168.11.231:6174', 'http://192.168.10.11:6174', 'http://dev-oa.ge.cn:6174', 'http://test-oa.ge.cn:6174'];
1078
+ /**
1079
+ * OA 页面运行时配置注入 key。
1080
+ * 使用字符串常量是为了兼容 dist 与源码组件并存时的 provide/inject 匹配。
1081
+ */
1082
+ var OA_VIEW_CONFIG_KEY = 'oa-view-config';
1083
+
1074
1084
  var _PatchFlagNames, _slotFlagsText;
1075
1085
  /**
1076
1086
  * Make a map and return a function for checking if a key
@@ -3908,10 +3918,11 @@ function useCookieTempFileUrl(url) {
3908
3918
  };
3909
3919
  }
3910
3920
 
3911
- // 默认白名单
3912
- var defaultWhiteUrls = ['http://192.168.11.231:6174', 'http://192.168.10.11:6174', 'http://dev-oa.ge.cn:6174', 'http://test-oa.ge.cn:6174'];
3913
- // 配置注入 key
3914
- var OA_VIEW_CONFIG_KEY = Symbol('oa-view-config');
3921
+ /**
3922
+ * 安装 OA 页面插件,并注入全局运行时配置。
3923
+ * @param app Vue 应用实例。
3924
+ * @param options 插件配置项。
3925
+ */
3915
3926
  var install = function install(app) {
3916
3927
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3917
3928
  var _a;
@@ -3931,11 +3942,11 @@ var plugin = {
3931
3942
  install: install
3932
3943
  };
3933
3944
  /**
3934
- * 向客户端获取数据
3935
- * @param eventName 事件名称
3936
- * @param params 客户端传递事件的参数
3937
- * @param immediate 是否立即返回
3938
- * @returns
3945
+ * 根据原生事件名称向客户端请求数据。
3946
+ * @param eventName 原生事件名称。
3947
+ * @param params 发送给客户端的参数对象。
3948
+ * @param immediate 是否启用超时保护。
3949
+ * @returns 返回客户端回传的数据结果。
3939
3950
  */
3940
3951
  function getDataByApp(eventName, params) {
3941
3952
  var immediate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
@@ -3960,4 +3971,4 @@ function getDataByApp(eventName, params) {
3960
3971
  });
3961
3972
  }
3962
3973
 
3963
- export { Message, MessageBox, OA_VIEW_CONFIG_KEY, closeAllModals, compareVersions, createDebounceFn, createModal, createVersionCheckRuntime, plugin as default, getAppVersion, getDataByApp, getTempFilePathForCookie, isCurrentVersionHigher, sendLaunchAppParamsLog, useCookieTempFileUrl, versionCheckRuntime };
3974
+ export { Message, MessageBox, OA_VIEW_CONFIG_KEY, closeAllModals, compareVersions, createDebounceFn, createModal, createVersionCheckRuntime, plugin as default, defaultWhiteUrls, getAppVersion, getDataByApp, getTempFilePathForCookie, isCurrentVersionHigher, sendLaunchAppParamsLog, useCookieTempFileUrl, versionCheckRuntime };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uni-oaview",
3
- "version": "1.9.00",
3
+ "version": "1.9.02",
4
4
  "description": "uniapp小程序组件库",
5
5
  "main": "dist/index.esm.js",
6
6
  "typings": "dist/index.d.ts",
@@ -0,0 +1,35 @@
1
+ /**
2
+ * OA 页面插件配置项。
3
+ */
4
+ export interface OaViewOptions {
5
+ /**
6
+ * 允许展示调试能力的白名单地址列表。
7
+ */
8
+ whiteUrls?: string[];
9
+ }
10
+
11
+ /**
12
+ * OA 页面运行时配置对象。
13
+ */
14
+ export interface OaViewConfig {
15
+ /**
16
+ * 当前生效的白名单地址列表。
17
+ */
18
+ whiteUrls: string[];
19
+ }
20
+
21
+ /**
22
+ * 默认白名单地址列表。
23
+ */
24
+ export const defaultWhiteUrls = [
25
+ 'http://192.168.11.231:6174',
26
+ 'http://192.168.10.11:6174',
27
+ 'http://dev-oa.ge.cn:6174',
28
+ 'http://test-oa.ge.cn:6174',
29
+ ];
30
+
31
+ /**
32
+ * OA 页面运行时配置注入 key。
33
+ * 使用字符串常量是为了兼容 dist 与源码组件并存时的 provide/inject 匹配。
34
+ */
35
+ export const OA_VIEW_CONFIG_KEY = 'oa-view-config' as const;
package/src/index.ts CHANGED
@@ -1,34 +1,24 @@
1
1
  import type { App, Plugin } from 'vue';
2
2
 
3
3
  import { sendLaunchAppParamsLog } from './utils';
4
+ import { defaultWhiteUrls, OA_VIEW_CONFIG_KEY } from './configs/oa-view-config';
5
+ import type { OaViewOptions } from './configs/oa-view-config';
4
6
  export * from './utils';
5
7
  export * from './composables';
8
+ export * from './configs/oa-view-config';
6
9
 
7
- // SDK 配置接口
8
- export interface OaViewOptions {
9
- whiteUrls?: string[];
10
- }
11
-
12
- // 默认白名单
13
- const defaultWhiteUrls = [
14
- 'http://192.168.11.231:6174',
15
- 'http://192.168.10.11:6174',
16
- 'http://dev-oa.ge.cn:6174',
17
- 'http://test-oa.ge.cn:6174',
18
- ];
19
-
20
- // 配置注入 key
21
- export const OA_VIEW_CONFIG_KEY = Symbol('oa-view-config');
22
-
10
+ /**
11
+ * 安装 OA 页面插件,并注入全局运行时配置。
12
+ * @param app Vue 应用实例。
13
+ * @param options 插件配置项。
14
+ */
23
15
  const install = (app: App, options: OaViewOptions = {}) => {
24
16
  // 合并配置
25
17
  const config = {
26
18
  whiteUrls: options.whiteUrls ?? defaultWhiteUrls,
27
19
  };
28
-
29
20
  // 全局 provide 配置
30
21
  app.provide(OA_VIEW_CONFIG_KEY, config);
31
-
32
22
  app.mixin({
33
23
  onLaunch(params: any) {
34
24
  sendLaunchAppParamsLog(params);
@@ -43,11 +33,11 @@ const plugin: Plugin = {
43
33
  export default plugin;
44
34
 
45
35
  /**
46
- * 向客户端获取数据
47
- * @param eventName 事件名称
48
- * @param params 客户端传递事件的参数
49
- * @param immediate 是否立即返回
50
- * @returns
36
+ * 根据原生事件名称向客户端请求数据。
37
+ * @param eventName 原生事件名称。
38
+ * @param params 发送给客户端的参数对象。
39
+ * @param immediate 是否启用超时保护。
40
+ * @returns 返回客户端回传的数据结果。
51
41
  */
52
42
  export function getDataByApp(eventName: string, params: Record<string, any>, immediate: boolean = false): Promise<any> {
53
43
  return new Promise((res, rej) => {
@@ -5,7 +5,7 @@ import { reportLog } from 'uniapp-log-sdk';
5
5
  * @param params
6
6
  */
7
7
  export function sendLaunchAppParamsLog(params: any) {
8
- console.log('小程序启动入参:', params);
8
+ console.log('【OA View】小程序启动入参:', params);
9
9
  // #ifndef H5
10
10
  try {
11
11
  const outputData = JSON.parse(JSON.stringify(params?.referrerInfo?.extraData));