uview-plus 3.8.18 → 3.8.37

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.
Files changed (39) hide show
  1. package/changelog.md +122 -0
  2. package/components/u-button/u-button.vue +60 -16
  3. package/components/u-calendar/calendar.js +4 -3
  4. package/components/u-calendar/header.vue +74 -32
  5. package/components/u-calendar/month.vue +9 -0
  6. package/components/u-calendar/props.js +5 -0
  7. package/components/u-calendar/u-calendar.vue +46 -0
  8. package/components/u-cropper/u-cropper.vue +409 -387
  9. package/components/u-input/u-input.vue +3 -1
  10. package/components/u-parse/node/node.vue +50 -20
  11. package/components/u-parse/u-parse.vue +38 -8
  12. package/components/u-poster/u-poster.vue +12 -10
  13. package/components/u-qrcode/qrcode.js +35 -29
  14. package/components/u-qrcode/u-qrcode.vue +17 -12
  15. package/components/u-toast/u-toast.vue +5 -1
  16. package/components/u-tooltip/u-tooltip.vue +1 -0
  17. package/index.scss +1 -0
  18. package/libs/config/config.js +2 -0
  19. package/libs/css/theme-legacy-bridge.scss +6 -0
  20. package/libs/css/theme-vars-core.scss +4 -0
  21. package/libs/i18n/locales/de.json +1 -0
  22. package/libs/i18n/locales/en.json +1 -0
  23. package/libs/i18n/locales/es.json +1 -0
  24. package/libs/i18n/locales/fr.json +1 -0
  25. package/libs/i18n/locales/ja.json +1 -0
  26. package/libs/i18n/locales/ko.json +1 -0
  27. package/libs/i18n/locales/ru.json +1 -0
  28. package/libs/i18n/locales/th.json +1 -0
  29. package/libs/i18n/locales/zh-Hans.json +1 -0
  30. package/libs/i18n/locales/zh-Hant.json +1 -0
  31. package/libs/root/index.js +5 -29
  32. package/libs/root/root.js +6 -2
  33. package/libs/theme/runtime.js +52 -3
  34. package/libs/theme/theme.js +13 -16
  35. package/package.json +1 -1
  36. package/theme.scss +0 -5
  37. package/types/comps/calendar.d.ts +5 -0
  38. package/types/comps/qrcode.d.ts +6 -0
  39. package/types/index.d.ts +6 -0
@@ -324,7 +324,9 @@ export default {
324
324
  },
325
325
  // 点击完成按钮时触发
326
326
  onConfirm(event) {
327
- this.$emit("confirm", this.innerValue);
327
+ const detail = event && event.detail ? event.detail : {};
328
+ const confirmValue = typeof detail.value !== "undefined" ? detail.value : this.innerValue;
329
+ this.$emit("confirm", confirmValue);
328
330
  },
329
331
  // 键盘高度发生变化的时候触发此事件
330
332
  // 兼容性:微信小程序2.7.0+、App 3.1.0+
@@ -185,6 +185,53 @@ export default {
185
185
  // #ifdef MP-WEIXIN
186
186
  toJSON () { return this },
187
187
  // #endif
188
+ /**
189
+ * @description 规范化链接地址
190
+ * @param {any} href
191
+ * @return {String}
192
+ */
193
+ normalizeHref (href) {
194
+ return typeof href === 'string' ? href.trim() : ''
195
+ },
196
+
197
+ /**
198
+ * @description 判断是否为外部链接
199
+ * @param {String} href
200
+ * @return {Boolean}
201
+ */
202
+ isExternalLink (href) {
203
+ return href.split('?')[0].includes('://')
204
+ },
205
+
206
+ /**
207
+ * @description 打开外部链接
208
+ * @param {String} href
209
+ */
210
+ openExternalLink (href) {
211
+ // #ifdef H5
212
+ window.open(href)
213
+ // #endif
214
+ // #ifdef MP
215
+ uni.setClipboardData({
216
+ data: href,
217
+ success: () =>
218
+ uni.showToast({
219
+ title: '链接已复制'
220
+ })
221
+ })
222
+ // #endif
223
+ // #ifdef APP-PLUS
224
+ try {
225
+ plus.runtime.openWeb(href)
226
+ } catch (e) { }
227
+ // #endif
228
+ // #ifdef APP-HARMONY
229
+ try {
230
+ plus.runtime.openURL(href)
231
+ } catch (e) { }
232
+ // #endif
233
+ },
234
+
188
235
  /**
189
236
  * @description 播放视频事件
190
237
  * @param {Event} e
@@ -341,7 +388,7 @@ export default {
341
388
  linkTap (e) {
342
389
  const node = e.currentTarget ? this.childs[e.currentTarget.dataset.i] : {}
343
390
  const attrs = node.attrs || e
344
- const href = attrs.href
391
+ const href = this.normalizeHref(attrs.href)
345
392
  this.root.$emit('linktap', Object.assign({
346
393
  innerText: this.root.getText(node.children || []) // 链接内的文本内容
347
394
  }, attrs))
@@ -349,27 +396,10 @@ export default {
349
396
  if (href[0] === '#') {
350
397
  // 跳转锚点
351
398
  this.root.navigateTo(href.substring(1)).catch(() => { })
352
- } else if (href.split('?')[0].includes('://')) {
399
+ } else if (this.isExternalLink(href)) {
353
400
  // 复制外部链接
354
401
  if (this.root.copyLink) {
355
- // #ifdef H5
356
- window.open(href)
357
- // #endif
358
- // #ifdef MP
359
- uni.setClipboardData({
360
- data: href,
361
- success: () =>
362
- uni.showToast({
363
- title: '链接已复制'
364
- })
365
- })
366
- // #endif
367
- // #ifdef APP-PLUS
368
- plus.runtime.openWeb(href)
369
- // #endif
370
- // #ifdef APP-HARMONY
371
- plus.runtime.openURL(href)
372
- // #endif
402
+ this.openExternalLink(href)
373
403
  }
374
404
  } else {
375
405
  // 跳转页面
@@ -130,6 +130,41 @@ export default {
130
130
  this._hook('onDetached')
131
131
  },
132
132
  methods: {
133
+ /**
134
+ * @description 规范化链接地址
135
+ * @param {any} href
136
+ * @return {String}
137
+ */
138
+ normalizeHref(href) {
139
+ return typeof href === 'string' ? href.trim() : ''
140
+ },
141
+
142
+ /**
143
+ * @description 判断是否为外部链接
144
+ * @param {String} href
145
+ * @return {Boolean}
146
+ */
147
+ isExternalLink(href) {
148
+ return href.split('?')[0].includes('://')
149
+ },
150
+
151
+ /**
152
+ * @description 打开外部链接
153
+ * @param {String} href
154
+ */
155
+ openExternalLink(href) {
156
+ // #ifdef APP-PLUS
157
+ try {
158
+ plus.runtime.openWeb(href)
159
+ } catch (e) { }
160
+ // #endif
161
+ // #ifdef APP-HARMONY
162
+ try {
163
+ plus.runtime.openURL(href)
164
+ } catch (e) { }
165
+ // #endif
166
+ },
167
+
133
168
  /**
134
169
  * @description 将锚点跳转的范围限定在一个 scroll-view 内
135
170
  * @param {Object} page scroll-view 所在页面的示例
@@ -420,7 +455,7 @@ export default {
420
455
  break
421
456
  // 链接点击
422
457
  case 'onLinkTap': {
423
- const href = message.attrs.href
458
+ const href = this.normalizeHref(message.attrs.href)
424
459
  this.$emit('linktap', message.attrs)
425
460
  if (href) {
426
461
  // 锚点跳转
@@ -430,15 +465,10 @@ export default {
430
465
  offset: message.offset
431
466
  })
432
467
  }
433
- } else if (href.includes('://')) {
468
+ } else if (this.isExternalLink(href)) {
434
469
  // 打开外链
435
470
  if (this.copyLink) {
436
- // #ifdef APP-PLUS
437
- plus.runtime.openWeb(href)
438
- // #endif
439
- // #ifdef APP-HARMONY
440
- plus.runtime.openURL(href)
441
- // #endif
471
+ this.openExternalLink(href)
442
472
  }
443
473
  } else {
444
474
  uni.navigateTo({
@@ -359,6 +359,14 @@ export default {
359
359
  const lineHeight = css.lineHeight ? this.convertRpxToPx(css.lineHeight) : 20;
360
360
  const lines = [];
361
361
  let currentLine = '';
362
+ const ellipsis = '...';
363
+ const appendEllipsis = (line) => {
364
+ let fitLine = line;
365
+ while (ctx.measureText(fitLine + ellipsis).width > maxWidth && fitLine.length > 0) {
366
+ fitLine = fitLine.substring(0, fitLine.length - 1);
367
+ }
368
+ return fitLine + ellipsis;
369
+ };
362
370
 
363
371
  for (let i = 0; i < text.length; i++) {
364
372
  const char = text[i];
@@ -367,20 +375,14 @@ export default {
367
375
 
368
376
  if (metrics.width > maxWidth && currentLine !== '') {
369
377
  lines.push(currentLine);
370
- currentLine = char;
371
378
 
372
379
  // 如果已达最大行数,添加省略号并结束
373
380
  if (lines.length === lineClamp) {
374
- if (metrics.width > maxWidth) {
375
- // 添加省略号
376
- let fitLine = currentLine.substring(0, currentLine.length - 1);
377
- while (ctx.measureText(fitLine + '...').width > maxWidth && fitLine.length > 0) {
378
- fitLine = fitLine.substring(0, fitLine.length - 1);
379
- }
380
- lines[lines.length - 1] = fitLine + '...';
381
- }
381
+ lines[lines.length - 1] = appendEllipsis(currentLine);
382
382
  break;
383
383
  }
384
+
385
+ currentLine = char;
384
386
  } else {
385
387
  currentLine = testLine;
386
388
  }
@@ -626,4 +628,4 @@ export default {
626
628
  }
627
629
  }
628
630
  }
629
- </style>
631
+ </style>
@@ -1023,11 +1023,12 @@ let QRCode = {};
1023
1023
  QRCode = function (opt) {
1024
1024
  //设置默认参数
1025
1025
  this.options = {
1026
- text: '',
1027
- size: 256,
1028
- correctLevel: 3,
1029
- background: '#ffffff',
1030
- foreground: '#000000',
1026
+ text: '',
1027
+ size: 256,
1028
+ correctLevel: 3,
1029
+ quietZone: 0,
1030
+ background: '#ffffff',
1031
+ foreground: '#000000',
1031
1032
  pdground: '#000000',
1032
1033
  image: '',
1033
1034
  imageSize: 30,
@@ -1103,30 +1104,35 @@ let QRCode = {};
1103
1104
  var ctx = '';
1104
1105
  ctx = options.ctx;
1105
1106
 
1106
- var count = qrCodeAlg.getModuleCount();
1107
- var ratioSize = options.size;
1108
- var ratioImgSize = options.imageSize;
1109
- //计算每个点的长宽
1110
- var tileW = (ratioSize / count).toPrecision(4);
1111
- var tileH = (ratioSize / count).toPrecision(4);
1112
- //绘制
1113
- for (var row = 0; row < count; row++) {
1114
- for (var col = 0; col < count; col++) {
1115
- var w = (Math.ceil((col + 1) * tileW) - Math.floor(col * tileW));
1116
- var h = (Math.ceil((row + 1) * tileH) - Math.floor(row * tileH));
1117
- var foreground = getForeGround({
1118
- row: row,
1119
- col: col,
1120
- count: count,
1121
- options: options
1122
- });
1123
- if (options.isNvue) {
1124
- ctx.setFillStyle(qrCodeAlg.modules[row][col] ? foreground : options.background);
1125
- } else {
1126
- ctx.fillStyle = qrCodeAlg.modules[row][col] ? foreground : options.background;
1127
- }
1128
- ctx.fillRect(Math.round(col * tileW), Math.round(row * tileH), w, h);
1129
- }
1107
+ var count = qrCodeAlg.getModuleCount();
1108
+ var quietZone = Math.max(0, Math.floor(options.quietZone || 0));
1109
+ var renderCount = count + quietZone * 2;
1110
+ var ratioSize = options.size;
1111
+ var ratioImgSize = options.imageSize;
1112
+ //计算每个点的长宽
1113
+ var tileW = (ratioSize / renderCount).toPrecision(4);
1114
+ var tileH = (ratioSize / renderCount).toPrecision(4);
1115
+ //绘制
1116
+ for (var row = 0; row < renderCount; row++) {
1117
+ for (var col = 0; col < renderCount; col++) {
1118
+ var w = (Math.ceil((col + 1) * tileW) - Math.floor(col * tileW));
1119
+ var h = (Math.ceil((row + 1) * tileH) - Math.floor(row * tileH));
1120
+ var qrRow = row - quietZone;
1121
+ var qrCol = col - quietZone;
1122
+ var isDark = qrRow >= 0 && qrCol >= 0 && qrRow < count && qrCol < count && qrCodeAlg.modules[qrRow][qrCol];
1123
+ var foreground = getForeGround({
1124
+ row: qrRow,
1125
+ col: qrCol,
1126
+ count: count,
1127
+ options: options
1128
+ });
1129
+ if (options.isNvue) {
1130
+ ctx.setFillStyle(isDark ? foreground : options.background);
1131
+ } else {
1132
+ ctx.fillStyle = isDark ? foreground : options.background;
1133
+ }
1134
+ ctx.fillRect(Math.round(col * tileW), Math.round(row * tileH), w, h);
1135
+ }
1130
1136
  }
1131
1137
  if (options.image) {
1132
1138
  var x = Number(((ratioSize - ratioImgSize) / 2).toFixed(2));
@@ -101,13 +101,17 @@ export default {
101
101
  type: Number,
102
102
  default: 40
103
103
  },
104
- lv: {
105
- type: Number,
106
- default: 3
107
- },
108
- onval: {
109
- type: Boolean,
110
- default: true
104
+ lv: {
105
+ type: Number,
106
+ default: 3
107
+ },
108
+ quietZone: {
109
+ type: Number,
110
+ default: 0
111
+ },
112
+ onval: {
113
+ type: Boolean,
114
+ default: true
111
115
  },
112
116
  loadMake: {
113
117
  type: Boolean,
@@ -218,11 +222,12 @@ export default {
218
222
  loadingText: that.loadingText, // loading文字
219
223
  text: that.val, // 生成内容
220
224
  size: that.sizeLocal, // 二维码大小
221
- background: that.background, // 背景色
222
- foreground: that.foreground, // 前景色
223
- pdground: that.pdground, // 定位角点颜色
224
- correctLevel: that.lv, // 容错级别
225
- image: that.icon, // 二维码图标
225
+ background: that.background, // 背景色
226
+ foreground: that.foreground, // 前景色
227
+ pdground: that.pdground, // 定位角点颜色
228
+ quietZone: that.quietZone, // 静区宽度
229
+ correctLevel: that.lv, // 容错级别
230
+ image: that.icon, // 二维码图标
226
231
  imageSize: that.iconSize,// 二维码图标大小
227
232
  cbResult: function (res) { // 生成二维码的回调
228
233
  that._result(res)
@@ -2,7 +2,7 @@
2
2
  <view class="u-toast">
3
3
  <u-overlay
4
4
  :show="isShow"
5
- :zIndex="tmpConfig.overlay ? tmpConfig.zIndex : -1"
5
+ :zIndex="tmpConfig.zIndex"
6
6
  :custom-style="overlayStyle"
7
7
  >
8
8
  <view
@@ -112,6 +112,10 @@
112
112
  }
113
113
  // 将遮罩设置为100%透明度,避免出现灰色背景
114
114
  style.backgroundColor = 'rgba(0, 0, 0, 0)'
115
+ // overlay=false时不阻止点击穿透
116
+ if (!this.tmpConfig.overlay) {
117
+ style.pointerEvents = 'none'
118
+ }
115
119
  return style
116
120
  },
117
121
  iconStyle() {
@@ -19,6 +19,7 @@
19
19
  :selectable="false"
20
20
  :style="{
21
21
  color: color,
22
+ fontSize: $u.addUnit(size),
22
23
  backgroundColor: bgColor && showTooltip && tooltipTop !== -10000 ? bgColor : 'transparent'
23
24
  }"
24
25
  >{{ text }}</text>
package/index.scss CHANGED
@@ -1,5 +1,6 @@
1
1
  /* #ifndef APP-NVUE */
2
2
  @import "./libs/css/theme-vars.scss";
3
+ @import "./libs/css/theme-legacy-bridge.scss";
3
4
  /* #endif */
4
5
 
5
6
  // 引入公共基础类
@@ -47,6 +47,8 @@ export default {
47
47
  customIcons: {}, // 自定义图标与unicode对应关系
48
48
  // 默认单位,可以通过配置为rpx,那么在用于传入组件大小参数为数值时,就默认为rpx
49
49
  unit: 'px',
50
+ // 是否由运行时主题同步原生导航栏、页面背景、tabBar等全局UI
51
+ nativeThemeSync: false,
50
52
  // 拦截器
51
53
  interceptor: {
52
54
  navbarLeftClick: null
@@ -0,0 +1,6 @@
1
+ @import "../../theme.scss";
2
+
3
+ @include up-export-legacy-light-vars(':root');
4
+ @include up-export-legacy-light-vars('page');
5
+ @include up-export-legacy-light-vars('body');
6
+ @include up-export-legacy-light-vars("[data-up-theme='light']");
@@ -10,6 +10,7 @@ body {
10
10
  --up-hover-bg-color: #e7ebf0;
11
11
  --up-page-bg-color: #f3f4f6;
12
12
  --up-card-bg-color: #ffffff;
13
+ --up-navbar-bg-color: #ffffff;
13
14
  --up-disabled-color: var(--up-light-disabled-color, #c8c9cc);
14
15
 
15
16
  --up-primary: var(--up-light-primary, #3c9cff);
@@ -61,6 +62,7 @@ body {
61
62
  --up-hover-bg-color: #343741;
62
63
  --up-page-bg-color: #1f1f1f;
63
64
  --up-card-bg-color: #1c1c1e;
65
+ --up-navbar-bg-color: #1c1c1e;
64
66
  --up-disabled-color: #4b5563;
65
67
 
66
68
  --up-primary: #3c9cff;
@@ -110,6 +112,7 @@ body {
110
112
  --up-hover-bg-color: #e7ebf0;
111
113
  --up-page-bg-color: #f3f4f6;
112
114
  --up-card-bg-color: #ffffff;
115
+ --up-navbar-bg-color: #ffffff;
113
116
  --up-disabled-color: var(--up-light-disabled-color, #c8c9cc);
114
117
 
115
118
  --up-primary: var(--up-light-primary, #3c9cff);
@@ -158,6 +161,7 @@ body {
158
161
  --up-hover-bg-color: #343741;
159
162
  --up-page-bg-color: #1f1f1f;
160
163
  --up-card-bg-color: #1c1c1e;
164
+ --up-navbar-bg-color: #1c1c1e;
161
165
  --up-disabled-color: #4b5563;
162
166
 
163
167
  --up-primary: #3c9cff;
@@ -34,6 +34,7 @@
34
34
  "up.calendar.chooseDates": "Datumsauswahl",
35
35
  "up.calendar.disabled": "Dieses Datum ist deaktiviert",
36
36
  "up.calendar.daysExceed": "Die Anzahl der ausgewählten Tage darf {days} Tage nicht überschreiten",
37
+ "up.calendar.today": "Heute",
37
38
  "up.cityLocate.locateCity": "Stadt lokalisieren",
38
39
  "up.cityLocate.fail": "Lokalisierung fehlgeschlagen, bitte klicken Sie zum Wiederholen.",
39
40
  "up.cityLocate.locating": "Lokalisierung läuft",
@@ -34,6 +34,7 @@
34
34
  "up.calendar.chooseDates": "Date selection",
35
35
  "up.calendar.disabled": "This date is disabled",
36
36
  "up.calendar.daysExceed": "The number of selected days cannot exceed {days} days",
37
+ "up.calendar.today": "Today",
37
38
  "up.cityLocate.locateCity": "Locate city",
38
39
  "up.cityLocate.fail": "Location failed, please click to retry.",
39
40
  "up.cityLocate.locating": "Locating",
@@ -34,6 +34,7 @@
34
34
  "up.calendar.chooseDates": "Selección de fecha",
35
35
  "up.calendar.disabled": "Esta fecha está deshabilitada",
36
36
  "up.calendar.daysExceed": "Los días seleccionados no pueden exceder {days} días",
37
+ "up.calendar.today": "Hoy",
37
38
  "up.cityLocate.locateCity": "Localizar ciudad",
38
39
  "up.cityLocate.fail": "Error de localización, haga clic para reintentar.",
39
40
  "up.cityLocate.locating": "Localizando",
@@ -34,6 +34,7 @@
34
34
  "up.calendar.chooseDates": "Sélection de dates",
35
35
  "up.calendar.disabled": "Cette date est désactivée",
36
36
  "up.calendar.daysExceed": "Le nombre de jours sélectionnés ne peut pas dépasser {days} jours",
37
+ "up.calendar.today": "Aujourd'hui",
37
38
  "up.cityLocate.locateCity": "Localiser la ville",
38
39
  "up.cityLocate.fail": "Échec de localisation, veuillez cliquer pour réessayer.",
39
40
  "up.cityLocate.locating": "Localisation en cours",
@@ -34,6 +34,7 @@
34
34
  "up.calendar.chooseDates": "日付選択",
35
35
  "up.calendar.disabled": "この日付は無効です",
36
36
  "up.calendar.daysExceed": "選択日数は{days}日を超えることはできません",
37
+ "up.calendar.today": "今日",
37
38
  "up.cityLocate.locateCity": "都市の位置を特定",
38
39
  "up.cityLocate.fail": "位置特定に失敗しました。再試行するにはクリックしてください。",
39
40
  "up.cityLocate.locating": "位置特定中",
@@ -34,6 +34,7 @@
34
34
  "up.calendar.chooseDates": "날짜 선택",
35
35
  "up.calendar.disabled": "해당 날짜는 사용할 수 없습니다",
36
36
  "up.calendar.daysExceed": "선택한 날짜 수가 {days}일을 초과할 수 없습니다",
37
+ "up.calendar.today": "오늘",
37
38
  "up.cityLocate.locateCity": "도시 위치 찾기",
38
39
  "up.cityLocate.fail": "위치 찾기 실패, 다시 시도하려면 클릭하세요.",
39
40
  "up.cityLocate.locating": "위치 찾는 중",
@@ -34,6 +34,7 @@
34
34
  "up.calendar.chooseDates": "Выбор даты",
35
35
  "up.calendar.disabled": "Эта дата отключена",
36
36
  "up.calendar.daysExceed": "Количество выбранных дней не может превышать {days} дней",
37
+ "up.calendar.today": "Сегодня",
37
38
  "up.cityLocate.locateCity": "Определение города",
38
39
  "up.cityLocate.fail": "Ошибка определения местоположения, нажмите для повтора.",
39
40
  "up.cityLocate.locating": "Определение местоположения",
@@ -34,6 +34,7 @@
34
34
  "up.calendar.chooseDates": "เลือกวันที่",
35
35
  "up.calendar.disabled": "วันที่นี้ถูกปิดการใช้งาน",
36
36
  "up.calendar.daysExceed": "จำนวนวันที่เลือกต้องไม่เกิน {days} วัน",
37
+ "up.calendar.today": "วันนี้",
37
38
  "up.cityLocate.locateCity": "ระบุตำแหน่งเมือง",
38
39
  "up.cityLocate.fail": "การระบุตำแหน่งล้มเหลว กรุณาคลิกเพื่อลองใหม่",
39
40
  "up.cityLocate.locating": "กำลังระบุตำแหน่ง",
@@ -34,6 +34,7 @@
34
34
  "up.calendar.chooseDates": "日期选择",
35
35
  "up.calendar.disabled": "该日期已禁用",
36
36
  "up.calendar.daysExceed": "选择天数不能超过{days}天",
37
+ "up.calendar.today": "今天",
37
38
  "up.cityLocate.locateCity": "定位城市",
38
39
  "up.cityLocate.fail": "定位失败,请点击重试。",
39
40
  "up.cityLocate.locating": "定位中",
@@ -34,6 +34,7 @@
34
34
  "up.calendar.chooseDates": "日期選擇",
35
35
  "up.calendar.disabled": "該日期已禁用",
36
36
  "up.calendar.daysExceed": "選擇天數不能超過{days}天",
37
+ "up.calendar.today": "今天",
37
38
  "up.cityLocate.locateCity": "定位城市",
38
39
  "up.cityLocate.fail": "定位失敗,請點擊重試。",
39
40
  "up.cityLocate.locating": "定位中",
@@ -1,4 +1,5 @@
1
1
  import { dirname, relative, resolve } from 'node:path'
2
+ import { fileURLToPath } from 'node:url'
2
3
  import process from 'node:process'
3
4
  import { existsSync, mkdirSync, statSync, writeFileSync } from 'node:fs'
4
5
 
@@ -8,13 +9,14 @@ import { transformNvuePage, transformPage } from './page.js'
8
9
  import { rebuildUpApp, registerUpApp } from './root.js'
9
10
  import { loadPagesJson, normalizePlatformPath, toArray } from './utils.js'
10
11
 
12
+ const rootLibPath = normalizePath(dirname(fileURLToPath(import.meta.url)))
13
+
11
14
  export default function UniUpRoot(options = {}) {
12
15
  const rootOptions = {
13
16
  enabledVirtualHost: false,
14
17
  enabledGlobalRef: false,
15
18
  rootFileName: 'App.up',
16
19
  autoCreateRootFile: true,
17
- autoCreateViteConfig: true,
18
20
  excludePages: [],
19
21
  ...options,
20
22
  }
@@ -50,14 +52,10 @@ export default function UniUpRoot(options = {}) {
50
52
  const projectInfo = detectProjectRoot()
51
53
  const rootPath = normalizePath(projectInfo.rootPath)
52
54
  const appUpPath = normalizePath(resolve(rootPath, `${rootFileName}.vue`))
55
+ const rootToastHostPath = normalizePath(resolve(rootLibPath, 'root-toast-host.vue'))
53
56
  const nvueRootPath = normalizePath(resolve(rootPath, 'uni_modules/uview-plus/libs/root/nvue-root.vue'))
54
57
  const themeRuntimePath = normalizePath(resolve(rootPath, 'uni_modules/uview-plus/libs/theme/runtime.js'))
55
58
  const pagesPath = normalizePath(resolve(rootPath, 'pages.json'))
56
- const projectBasePath = normalizePath(
57
- projectInfo.projectType === 'cli' ? resolve(rootPath, '..') : rootPath
58
- )
59
- const viteConfigTsPath = normalizePath(resolve(projectBasePath, 'vite.config.ts'))
60
- const viteConfigJsPath = normalizePath(resolve(projectBasePath, 'vite.config.js'))
61
59
  const excludedPaths = toArray(rootOptions.excludePages)
62
60
  .filter(Boolean)
63
61
  .map(path => normalizePath(resolve(rootPath, path)))
@@ -92,27 +90,6 @@ export default function UniUpRoot(options = {}) {
92
90
  writeFileSync(appUpPath, defaultRootSfc, 'utf-8')
93
91
  }
94
92
 
95
- const ensureViteConfigFile = () => {
96
- if (!rootOptions.autoCreateViteConfig) return
97
- if (existsSync(viteConfigTsPath) || existsSync(viteConfigJsPath)) return
98
-
99
- const template = `import { defineConfig } from "vite";
100
- import uni from "@dcloudio/vite-plugin-uni";
101
- import UniUpRoot from "./src/uni_modules/uview-plus/libs/root/index.js";
102
-
103
- export default defineConfig({
104
- plugins: [
105
- UniUpRoot({
106
- rootFileName: "${rootFileName}",
107
- }),
108
- uni(),
109
- ],
110
- });
111
- `
112
-
113
- writeFileSync(viteConfigTsPath, template, 'utf-8')
114
- }
115
-
116
93
  const refreshPagesJson = () => {
117
94
  if (!existsSync(pagesPath)) return
118
95
  const mtimeMs = statSync(pagesPath).mtimeMs
@@ -128,7 +105,6 @@ export default defineConfig({
128
105
  hasPlatformPlugin = plugins.some(v => v.name === 'vite-plugin-uni-platform')
129
106
  },
130
107
  buildStart() {
131
- ensureViteConfigFile()
132
108
  ensureRootFile()
133
109
  refreshPagesJson()
134
110
  },
@@ -139,7 +115,7 @@ export default defineConfig({
139
115
 
140
116
  const filterMain = createFilter(mainFiles)
141
117
  if (filterMain(cleanId)) {
142
- ms = await registerUpApp(code, rootFileName)
118
+ ms = await registerUpApp(code, rootFileName, getRelativeImportPath(cleanId, rootToastHostPath))
143
119
  }
144
120
 
145
121
  const filterUpRoot = createFilter(appUpPath)
package/libs/root/root.js CHANGED
@@ -2,11 +2,15 @@ import { MagicString } from 'vue/compiler-sfc'
2
2
 
3
3
  import { parseSFC } from './utils.js'
4
4
 
5
- export async function registerUpApp(code, fileName = 'App.up') {
5
+ export async function registerUpApp(
6
+ code,
7
+ fileName = 'App.up',
8
+ rootToastHostPath = './uni_modules/uview-plus/libs/root/root-toast-host.vue'
9
+ ) {
6
10
  const ms = new MagicString(code)
7
11
 
8
12
  const importCode = `import GlobalUpRoot from "./${fileName}.vue";
9
- import UpRootToastHost from "./uni_modules/uview-plus/libs/root/root-toast-host.vue";`
13
+ import UpRootToastHost from "${rootToastHostPath}";`
10
14
  const vueUseComponentCode = 'app.component("global-up-root", GlobalUpRoot);\napp.component("ku-root-toast-host", UpRootToastHost);'
11
15
 
12
16
  ms.prepend(`${importCode}\n`).replace(