uni-oaview 1.9.1 → 1.9.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/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
  ---
@@ -5,9 +5,13 @@
5
5
  <p class="subtitle">{{ state.subtitle }}</p>
6
6
  <view class="divider" />
7
7
  <view class="submit-buttons">
8
- <view class="cancel-button" @click="submitClick('cancel')">{{ state.cancelText }}</view>
8
+ <view class="cancel-button" :style="{ color: state.cancelTextColor }" @click="submitClick('cancel')">
9
+ {{ state.cancelText }}
10
+ </view>
9
11
  <view class="divider-vertical" />
10
- <view class="confirm-button" @click="submitClick('confirm')">{{ state.confirmText }}</view>
12
+ <view class="confirm-button" :style="{ color: state.confirmTextColor }" @click="submitClick('confirm')">
13
+ {{ state.confirmText }}
14
+ </view>
11
15
  </view>
12
16
  </view>
13
17
  </uni-popup>
@@ -27,6 +31,8 @@
27
31
  subtitle: '',
28
32
  confirmText: '确定',
29
33
  cancelText: '取消',
34
+ confirmTextColor: '#3d73ff',
35
+ cancelTextColor: '#1c202b',
30
36
  });
31
37
 
32
38
  let innerCallback: any = null;
@@ -48,12 +54,14 @@
48
54
  if (!isPageAlive.value) return;
49
55
  isShow.value = true;
50
56
  setTimeout(() => {
51
- const { title, subtitle, confirmText, cancelText, callback } = params;
57
+ const { title, subtitle, confirmText, cancelText, confirmTextColor, cancelTextColor, callback } = params;
52
58
  innerCallback = callback;
53
59
  state.title = title || '';
54
60
  state.subtitle = subtitle || '';
55
61
  state.confirmText = confirmText || '确定';
56
62
  state.cancelText = cancelText || '取消';
63
+ state.confirmTextColor = confirmTextColor || '#3d73ff';
64
+ state.cancelTextColor = cancelTextColor || '#1c202b';
57
65
  popupRef.value?.open('center');
58
66
  });
59
67
  });
@@ -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;
@@ -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
@@ -192,6 +192,27 @@ declare function createModal<E extends ModalBaseEvents = ModalBaseEvents>(compon
192
192
  */
193
193
  declare function closeAllModals(): void;
194
194
 
195
+ /**
196
+ * 新版确认弹窗的按钮配置。
197
+ */
198
+ interface MessageBoxConfirmOptions {
199
+ /**
200
+ * 确认按钮的展示文案。
201
+ */
202
+ confirmText?: string;
203
+ /**
204
+ * 取消按钮的展示文案。
205
+ */
206
+ cancelText?: string;
207
+ /**
208
+ * 确认按钮文案颜色,未传时使用组件默认颜色。
209
+ */
210
+ confirmTextColor?: string;
211
+ /**
212
+ * 取消按钮文案颜色,未传时使用组件默认颜色。
213
+ */
214
+ cancelTextColor?: string;
215
+ }
195
216
  /**
196
217
  * 新版确认弹窗(按Figma设计)
197
218
  *
@@ -205,6 +226,12 @@ declare function closeAllModals(): void;
205
226
  * import { MessageBox } from '@/uni-oaview/src/utils/message-box'
206
227
  *
207
228
  * MessageBox.confirm('删除音频', '删除后将不可恢复', '删除', '取消')
229
+ * MessageBox.confirm('删除音频', '删除后将不可恢复', {
230
+ * confirmText: '删除',
231
+ * confirmTextColor: '#ff4d4f',
232
+ * cancelText: '再想想',
233
+ * cancelTextColor: '#86909c',
234
+ * })
208
235
  * .then(() => {
209
236
  * console.log('用户点击了确定')
210
237
  * })
@@ -218,11 +245,11 @@ declare const MessageBox: {
218
245
  * 新版确认弹窗
219
246
  * @param title 标题
220
247
  * @param subtitle 副标题
221
- * @param confirmText 确定按钮文本,默认'确定'
248
+ * @param confirmTextOrOptions 确定按钮文本,或按钮配置
222
249
  * @param cancelText 取消按钮文本,默认'取消'
223
250
  * @returns Promise<string> 确定时resolve,取消时reject
224
251
  */
225
- confirm(title: string, subtitle: string, confirmText?: string, cancelText?: string): Promise<unknown>;
252
+ confirm(title: string, subtitle: string, confirmTextOrOptions?: string | MessageBoxConfirmOptions, cancelText?: string): Promise<unknown>;
226
253
  };
227
254
 
228
255
  /**
@@ -319,18 +346,42 @@ declare function useCookieTempFileUrl(url: string): {
319
346
  tempUrl: _mp_rt1_vue___Ref<string>;
320
347
  };
321
348
 
349
+ /**
350
+ * OA 页面插件配置项。
351
+ */
322
352
  interface OaViewOptions {
353
+ /**
354
+ * 允许展示调试能力的白名单地址列表。
355
+ */
323
356
  whiteUrls?: string[];
324
357
  }
325
- declare const OA_VIEW_CONFIG_KEY: unique symbol;
358
+ /**
359
+ * OA 页面运行时配置对象。
360
+ */
361
+ interface OaViewConfig {
362
+ /**
363
+ * 当前生效的白名单地址列表。
364
+ */
365
+ whiteUrls: string[];
366
+ }
367
+ /**
368
+ * 默认白名单地址列表。
369
+ */
370
+ declare const defaultWhiteUrls: string[];
371
+ /**
372
+ * OA 页面运行时配置注入 key。
373
+ * 使用字符串常量是为了兼容 dist 与源码组件并存时的 provide/inject 匹配。
374
+ */
375
+ declare const OA_VIEW_CONFIG_KEY: "oa-view-config";
376
+
326
377
  declare const plugin: Plugin;
327
378
  /**
328
- * 向客户端获取数据
329
- * @param eventName 事件名称
330
- * @param params 客户端传递事件的参数
331
- * @param immediate 是否立即返回
332
- * @returns
379
+ * 根据原生事件名称向客户端请求数据。
380
+ * @param eventName 原生事件名称。
381
+ * @param params 发送给客户端的参数对象。
382
+ * @param immediate 是否启用超时保护。
383
+ * @returns 返回客户端回传的数据结果。
333
384
  */
334
385
  declare function getDataByApp(eventName: string, params: Record<string, any>, immediate?: boolean): Promise<any>;
335
386
 
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 };
387
+ 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));
@@ -823,6 +823,14 @@ function closeAllModals() {
823
823
  });
824
824
  }
825
825
 
826
+ /**
827
+ * 判断传入值是否为新版确认弹窗配置对象。
828
+ *
829
+ * 这里仅接受普通对象,避免把异常 truthy 值误判为配置对象。
830
+ */
831
+ var isConfirmOptions = function isConfirmOptions(value) {
832
+ return Object.prototype.toString.call(value) === '[object Object]';
833
+ };
826
834
  /**
827
835
  * 新版确认弹窗(按Figma设计)
828
836
  *
@@ -836,6 +844,12 @@ function closeAllModals() {
836
844
  * import { MessageBox } from '@/uni-oaview/src/utils/message-box'
837
845
  *
838
846
  * MessageBox.confirm('删除音频', '删除后将不可恢复', '删除', '取消')
847
+ * MessageBox.confirm('删除音频', '删除后将不可恢复', {
848
+ * confirmText: '删除',
849
+ * confirmTextColor: '#ff4d4f',
850
+ * cancelText: '再想想',
851
+ * cancelTextColor: '#86909c',
852
+ * })
839
853
  * .then(() => {
840
854
  * console.log('用户点击了确定')
841
855
  * })
@@ -849,12 +863,22 @@ var MessageBox = {
849
863
  * 新版确认弹窗
850
864
  * @param title 标题
851
865
  * @param subtitle 副标题
852
- * @param confirmText 确定按钮文本,默认'确定'
866
+ * @param confirmTextOrOptions 确定按钮文本,或按钮配置
853
867
  * @param cancelText 取消按钮文本,默认'取消'
854
868
  * @returns Promise<string> 确定时resolve,取消时reject
855
869
  */
856
- confirm: function confirm(title, subtitle, confirmText, cancelText) {
870
+ confirm: function confirm(title, subtitle, confirmTextOrOptions, cancelText) {
857
871
  return new Promise(function (res, rej) {
872
+ /**
873
+ * 统一兼容旧版字符串参数和新版对象参数,减少调用方迁移成本。
874
+ */
875
+ var options = typeof confirmTextOrOptions === 'string' ? {
876
+ confirmText: confirmTextOrOptions,
877
+ cancelText: cancelText
878
+ } : isConfirmOptions(confirmTextOrOptions) ? confirmTextOrOptions : {};
879
+ /**
880
+ * 弹框关闭后通过回调通知调用方点击结果。
881
+ */
858
882
  var callback = function callback(type) {
859
883
  if (type === 'confirm') {
860
884
  res('');
@@ -865,8 +889,10 @@ var MessageBox = {
865
889
  uni.$emit(OPEN_CONFIRM_BOX_NEW, {
866
890
  title: title,
867
891
  subtitle: subtitle,
868
- confirmText: confirmText,
869
- cancelText: cancelText,
892
+ confirmText: options.confirmText,
893
+ cancelText: options.cancelText,
894
+ confirmTextColor: options.confirmTextColor,
895
+ cancelTextColor: options.cancelTextColor,
870
896
  callback: callback
871
897
  });
872
898
  });
@@ -1071,6 +1097,16 @@ function createVersionCheckRuntime() {
1071
1097
  /** 默认版本检测运行时单例 */
1072
1098
  var versionCheckRuntime = createVersionCheckRuntime();
1073
1099
 
1100
+ /**
1101
+ * 默认白名单地址列表。
1102
+ */
1103
+ 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'];
1104
+ /**
1105
+ * OA 页面运行时配置注入 key。
1106
+ * 使用字符串常量是为了兼容 dist 与源码组件并存时的 provide/inject 匹配。
1107
+ */
1108
+ var OA_VIEW_CONFIG_KEY = 'oa-view-config';
1109
+
1074
1110
  var _PatchFlagNames, _slotFlagsText;
1075
1111
  /**
1076
1112
  * Make a map and return a function for checking if a key
@@ -3908,10 +3944,11 @@ function useCookieTempFileUrl(url) {
3908
3944
  };
3909
3945
  }
3910
3946
 
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');
3947
+ /**
3948
+ * 安装 OA 页面插件,并注入全局运行时配置。
3949
+ * @param app Vue 应用实例。
3950
+ * @param options 插件配置项。
3951
+ */
3915
3952
  var install = function install(app) {
3916
3953
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3917
3954
  var _a;
@@ -3931,11 +3968,11 @@ var plugin = {
3931
3968
  install: install
3932
3969
  };
3933
3970
  /**
3934
- * 向客户端获取数据
3935
- * @param eventName 事件名称
3936
- * @param params 客户端传递事件的参数
3937
- * @param immediate 是否立即返回
3938
- * @returns
3971
+ * 根据原生事件名称向客户端请求数据。
3972
+ * @param eventName 原生事件名称。
3973
+ * @param params 发送给客户端的参数对象。
3974
+ * @param immediate 是否启用超时保护。
3975
+ * @returns 返回客户端回传的数据结果。
3939
3976
  */
3940
3977
  function getDataByApp(eventName, params) {
3941
3978
  var immediate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
@@ -3960,4 +3997,4 @@ function getDataByApp(eventName, params) {
3960
3997
  });
3961
3998
  }
3962
3999
 
3963
- export { Message, MessageBox, OA_VIEW_CONFIG_KEY, closeAllModals, compareVersions, createDebounceFn, createModal, createVersionCheckRuntime, plugin as default, getAppVersion, getDataByApp, getTempFilePathForCookie, isCurrentVersionHigher, sendLaunchAppParamsLog, useCookieTempFileUrl, versionCheckRuntime };
4000
+ 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.01",
3
+ "version": "1.9.03",
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) => {
@@ -1,5 +1,39 @@
1
1
  import { OPEN_CONFIRM_BOX_NEW } from '../../constants';
2
2
 
3
+ /**
4
+ * 新版确认弹窗的按钮配置。
5
+ */
6
+ interface MessageBoxConfirmOptions {
7
+ /**
8
+ * 确认按钮的展示文案。
9
+ */
10
+ confirmText?: string;
11
+
12
+ /**
13
+ * 取消按钮的展示文案。
14
+ */
15
+ cancelText?: string;
16
+
17
+ /**
18
+ * 确认按钮文案颜色,未传时使用组件默认颜色。
19
+ */
20
+ confirmTextColor?: string;
21
+
22
+ /**
23
+ * 取消按钮文案颜色,未传时使用组件默认颜色。
24
+ */
25
+ cancelTextColor?: string;
26
+ }
27
+
28
+ /**
29
+ * 判断传入值是否为新版确认弹窗配置对象。
30
+ *
31
+ * 这里仅接受普通对象,避免把异常 truthy 值误判为配置对象。
32
+ */
33
+ const isConfirmOptions = (value: unknown): value is MessageBoxConfirmOptions => {
34
+ return Object.prototype.toString.call(value) === '[object Object]';
35
+ };
36
+
3
37
  /**
4
38
  * 新版确认弹窗(按Figma设计)
5
39
  *
@@ -13,6 +47,12 @@ import { OPEN_CONFIRM_BOX_NEW } from '../../constants';
13
47
  * import { MessageBox } from '@/uni-oaview/src/utils/message-box'
14
48
  *
15
49
  * MessageBox.confirm('删除音频', '删除后将不可恢复', '删除', '取消')
50
+ * MessageBox.confirm('删除音频', '删除后将不可恢复', {
51
+ * confirmText: '删除',
52
+ * confirmTextColor: '#ff4d4f',
53
+ * cancelText: '再想想',
54
+ * cancelTextColor: '#86909c',
55
+ * })
16
56
  * .then(() => {
17
57
  * console.log('用户点击了确定')
18
58
  * })
@@ -26,12 +66,33 @@ export const MessageBox = {
26
66
  * 新版确认弹窗
27
67
  * @param title 标题
28
68
  * @param subtitle 副标题
29
- * @param confirmText 确定按钮文本,默认'确定'
69
+ * @param confirmTextOrOptions 确定按钮文本,或按钮配置
30
70
  * @param cancelText 取消按钮文本,默认'取消'
31
71
  * @returns Promise<string> 确定时resolve,取消时reject
32
72
  */
33
- confirm(title: string, subtitle: string, confirmText?: string, cancelText?: string) {
73
+ confirm(
74
+ title: string,
75
+ subtitle: string,
76
+ confirmTextOrOptions?: string | MessageBoxConfirmOptions,
77
+ cancelText?: string,
78
+ ) {
34
79
  return new Promise((res, rej) => {
80
+ /**
81
+ * 统一兼容旧版字符串参数和新版对象参数,减少调用方迁移成本。
82
+ */
83
+ const options: MessageBoxConfirmOptions =
84
+ typeof confirmTextOrOptions === 'string'
85
+ ? {
86
+ confirmText: confirmTextOrOptions,
87
+ cancelText,
88
+ }
89
+ : isConfirmOptions(confirmTextOrOptions)
90
+ ? confirmTextOrOptions
91
+ : {};
92
+
93
+ /**
94
+ * 弹框关闭后通过回调通知调用方点击结果。
95
+ */
35
96
  const callback = (type: 'confirm' | 'cancel') => {
36
97
  if (type === 'confirm') {
37
98
  res('');
@@ -42,8 +103,10 @@ export const MessageBox = {
42
103
  uni.$emit(OPEN_CONFIRM_BOX_NEW, {
43
104
  title,
44
105
  subtitle,
45
- confirmText,
46
- cancelText,
106
+ confirmText: options.confirmText,
107
+ cancelText: options.cancelText,
108
+ confirmTextColor: options.confirmTextColor,
109
+ cancelTextColor: options.cancelTextColor,
47
110
  callback,
48
111
  });
49
112
  });
@@ -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));