wui-components-v2 1.1.4 → 1.1.6

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.
@@ -0,0 +1,131 @@
1
+ <script setup lang="ts">
2
+ import { computed, defineEmits, onBeforeMount, ref } from 'vue'
3
+ import WuiUpdateComponent from '../wui-update-component/wui-update-component.vue'
4
+
5
+ defineOptions({
6
+ name: 'WuiAutoUpdateComponent',
7
+ })
8
+ const prop = defineProps({
9
+ hydrocarbonProgramToken: {
10
+ type: String,
11
+ default: '',
12
+ },
13
+ baseUrl: {
14
+ type: String,
15
+ default: '',
16
+ },
17
+ sourceId: {
18
+ type: String,
19
+ default: '',
20
+ },
21
+ appId: {
22
+ type: String,
23
+ default: '',
24
+ },
25
+ })
26
+ const entities = ref([])
27
+ // 弹窗开关
28
+ const show = ref(false)
29
+
30
+ const isUpdate = ref(0)
31
+ // 当前版本
32
+ const currentVersion = ref('')
33
+
34
+ // 最新版本
35
+ const latestVersion = ref('')
36
+
37
+ // 弹框进入时检查更新
38
+ async function beforeEnter() {
39
+ // 获取当前应用版本号
40
+ const v1 = await new Promise<string>((resolve, reject) => {
41
+ plus.runtime.getProperty(plus.runtime.appid || '', (widgetInfo) => {
42
+ resolve(widgetInfo.version || '')
43
+ })
44
+ console.log(reject)
45
+ })
46
+ currentVersion.value = v1
47
+ // 获取接口最新版本号
48
+ uni.request({
49
+ url:
50
+ `${prop.baseUrl
51
+ }/v3/mstruc/data?sourceId=${prop.sourceId}&depth=1&sortColIds=创建时间_DESC&pageNo=1&pageSize=1&c_app编码_equals=${prop.appId}&c_标记删除_equals=否`,
52
+ method: 'GET',
53
+ header: {
54
+ 'hydrocarbon-program-token': prop.hydrocarbonProgramToken,
55
+ },
56
+ success: (res: any) => {
57
+ if (res.statusCode === 200) {
58
+ if (res.data.entities.length > 0) {
59
+ latestVersion.value = res.data.entities[0]['版本号'] // 最新版本号
60
+ isUpdate.value = compareVersions(currentVersion.value, latestVersion.value) // 比较版本号
61
+ if (isUpdate.value !== 0) {
62
+ show.value = true// 显示弹窗
63
+ }
64
+ entities.value = res.data.entities // 获取接口数据
65
+ }
66
+ }
67
+ },
68
+ fail: (err) => {
69
+ console.log('接口版本err:', err)
70
+ },
71
+ })
72
+ }
73
+
74
+ onBeforeMount(() => {
75
+ // #ifdef APP-PLUS
76
+ beforeEnter()
77
+ // #endif
78
+ })
79
+
80
+ // 版本号比对 1:大于当前版本,-1:小于当前版本,0:版本号相同
81
+ function compareVersions(v1: string, v2: string) {
82
+ // 接口版本
83
+ const v2Parts = v2.split('.').map(Number)
84
+ // 本地版本
85
+ const v1Parts = v1.split('.').map(Number)
86
+ for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
87
+ const part1 = v1Parts[i] || 0
88
+ const part2 = v2Parts[i] || 0
89
+ if (part1 !== part2)
90
+ return part1 < part2 ? 1 : -1
91
+ }
92
+ return 0
93
+ }
94
+ </script>
95
+
96
+ <template>
97
+ <WuiUpdateComponent
98
+ :show="show" :app-id="prop.appId" :hydrocarbon-program-token="prop.hydrocarbonProgramToken"
99
+ :base-url="prop.baseUrl" :source-id="prop.sourceId"
100
+ />
101
+ </template>
102
+
103
+ <style lang="scss" scoped>
104
+ .updateBox {
105
+ display: flex;
106
+ flex-direction: column;
107
+ align-items: center;
108
+ width: 600rpx;
109
+ min-height: 200rpx;
110
+ padding: 32rpx;
111
+ background-color: #fff;
112
+ border-radius: 32rpx;
113
+
114
+ .calc {
115
+ width: 550rpx;
116
+ margin-top: 40rpx;
117
+ text-align: center;
118
+ }
119
+ }
120
+
121
+ .loadingBox {
122
+ display: flex;
123
+ align-items: center;
124
+ justify-content: center;
125
+ width: 600rpx;
126
+ height: 200rpx;
127
+ padding: 32rpx;
128
+ background-color: #fff;
129
+ border-radius: 32rpx;
130
+ }
131
+ </style>
@@ -1,6 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { defineOptions, defineProps } from 'vue'
3
3
  import LoginForm from '../login-form/login-form.vue'
4
+ import { useManualTheme } from '../../composables/useManualTheme'
4
5
 
5
6
  defineOptions({
6
7
  name: 'WuiLogin',
@@ -8,10 +9,13 @@ defineOptions({
8
9
  defineProps<{
9
10
  loginlog: any
10
11
  }>()
12
+ const {
13
+ currentThemeColor,
14
+ } = useManualTheme()
11
15
  </script>
12
16
 
13
17
  <template>
14
- <view class="h-[calc(100vh-44px)] flex flex-col bg-#4E7FFF .dark:bg-[--wot-dark-background9]">
18
+ <view class="h-[calc(100vh-44px)] flex flex-col .dark:bg-[--wot-dark-background9]" :style="{ backgroundColor: currentThemeColor.primary }">
15
19
  <!-- <view class="flex flex-col items-center justify-center pa-3 pb-5">
16
20
  <wd-img :width="100" :height="100" round :src="loginlog" />
17
21
  <view class="text-center">
@@ -7,6 +7,8 @@ import { menu } from '../../api/menu'
7
7
  import DemoCard from '../demo-card/demo-card.vue'
8
8
  import { useManualTheme } from '../../composables/useManualTheme'
9
9
  import { useGlobalToast } from '../../composables/useGlobalToast'
10
+ import { useUser } from '../../composables/useUser'
11
+ import { formatChineseDate, generateGradientColor } from '../../utils'
10
12
 
11
13
  defineOptions({
12
14
  name: 'WuiMenus',
@@ -21,6 +23,7 @@ const props = defineProps({
21
23
  default: () => { },
22
24
  },
23
25
  })
26
+ const user = useUser().getUserInfo()
24
27
  const router = useRouter()
25
28
  const toast = useGlobalToast()
26
29
  interface Icon {
@@ -166,10 +169,32 @@ function queryList() {
166
169
  <template>
167
170
  <z-paging ref="paging" v-model="menuList" :loading-more-enabled="false" @query="queryList" @on-refresh="props.load">
168
171
  <template #top>
169
- <slot name="top" />
172
+ <slot name="top" :style="{ background: currentThemeColor.primary }" />
170
173
  </template>
171
- <view>
172
- <view class="h-3" />
174
+ <view class="position-relative">
175
+ <view style="box-sizing: border-box; padding: 20px; position: absolute;z-index: -1; height: 350rpx;width: 100%; background: linear-gradient( 180deg, #2094FF 0%, rgba(32,148,255,0.3) 100%);" :style="{ background: generateGradientColor(currentThemeColor.primary) }">
176
+ <view class="flex items-center gap-2 color-white">
177
+ <image
178
+ class="h-10 w-10 border-rd-100%"
179
+ style="border:2px solid #fff;"
180
+ src="../../static/hader.png"
181
+ mode="scaleToFill"
182
+ />
183
+ <view>
184
+ <view>你好,{{ user.name }}</view>
185
+ </view>
186
+ </view>
187
+ <view style="padding: 20rpx 0;" class="color-white">
188
+ {{ formatChineseDate() }}
189
+ </view>
190
+ </view>
191
+ <image
192
+ class="h-30 w-50"
193
+ style="position: absolute;z-index: -1;top: 0; right: 0;"
194
+ src="../../static/home.png"
195
+ mode="scaleToFill"
196
+ />
197
+ <view class="h-3 p-12" />
173
198
  <DemoCard v-for="(item, index) in filtermenu" :key="index" :title="item.title">
174
199
  <template #content>
175
200
  <view class="border-rd-2 bg-white pa-1 dark:bg-[var(--wot-dark-background2)]">
@@ -4,11 +4,15 @@ import {
4
4
  useMessage,
5
5
  } from 'wot-design-uni'
6
6
  import { useUser } from '../../composables/useUser'
7
+ import { generateGradientColor } from '../../utils'
8
+ import { useManualTheme } from '../../composables/useManualTheme'
7
9
 
8
10
  defineOptions({
9
11
  name: 'WuiUser',
10
12
  })
11
-
13
+ const {
14
+ currentThemeColor,
15
+ } = useManualTheme()
12
16
  const user = useUser().getUserInfo()
13
17
  const message = useMessage()
14
18
  const userInfo = ref({
@@ -53,7 +57,7 @@ function setting() {
53
57
  <view class="user">
54
58
  <view class="top-box">
55
59
  <!-- 用户头部信息 -->
56
- <view class="user-header">
60
+ <view class="user-header" :style="{ background: generateGradientColor(currentThemeColor.primary, 135, 1, 0.7) }">
57
61
  <view class="user-info">
58
62
  <!-- <img src="user.avatar" class="avatar" alt="用户头像"> -->
59
63
  <image class="avatar" src="./user-avatar-fill.png" />
package/index.ts CHANGED
@@ -20,6 +20,7 @@ import WuidetailsPage from './components/wui-details-page/wui-details-page.vue'
20
20
  import WuiUpdateComponent from './components/wui-update-component/wui-update-component.vue'
21
21
  import WuiScanBindingSensor from './components/wui-scan-binding-sensor/wui-scan-binding-sensor.vue'
22
22
  import WuiUser from './components/wui-user/wui-user.vue'
23
+ import wuiAutoUpdateComponent from './components/wui-auto-update-component/wui-auto-update-component.vue'
23
24
  // 组件列表
24
25
  const coms: Array<{ name: string }> = [
25
26
  WuiSystemSettings,
@@ -34,6 +35,7 @@ const coms: Array<{ name: string }> = [
34
35
  WuiUpdateComponent,
35
36
  WuiScanBindingSensor,
36
37
  WuiUser,
38
+ wuiAutoUpdateComponent,
37
39
  ]
38
40
 
39
41
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wui-components-v2",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "wui 组件库",
5
5
  "author": "wgxshh",
6
6
  "license": "MIT",
Binary file
Binary file
package/utils/index.ts CHANGED
@@ -309,3 +309,98 @@ function toArray(value: string) {
309
309
  }
310
310
  return val
311
311
  }
312
+
313
+ /**
314
+ * 根据目标颜色生成渐变色字符串
315
+ * @param color - 目标颜色,可以是十六进制颜色或RGB颜色
316
+ * @param angle - 渐变角度,默认为180deg
317
+ * @param startOpacity - 起始透明度,默认为1(不透明)
318
+ * @param endOpacity - 结束透明度,默认为0.3
319
+ * @returns 渐变色字符串
320
+ */
321
+ export function generateGradientColor(
322
+ color: string,
323
+ angle: number = 180,
324
+ startOpacity: number = 1,
325
+ endOpacity: number = 0.3,
326
+ ): string {
327
+ // 处理十六进制颜色转换为RGB
328
+ const hexToRgb = (hex: string): { r: number, g: number, b: number } | null => {
329
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
330
+ return result
331
+ ? {
332
+ r: Number.parseInt(result[1], 16),
333
+ g: Number.parseInt(result[2], 16),
334
+ b: Number.parseInt(result[3], 16),
335
+ }
336
+ : null
337
+ }
338
+
339
+ // 将RGB颜色转换为rgba格式
340
+ const toRgba = (color: string, opacity: number): string => {
341
+ if (color.startsWith('#')) {
342
+ const rgb = hexToRgb(color)
343
+ if (rgb) {
344
+ return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${opacity})`
345
+ }
346
+ }
347
+ else if (color.startsWith('rgb(')) {
348
+ // 处理rgb()格式
349
+ const rgbValues = color.match(/\d+/g)
350
+ if (rgbValues && rgbValues.length === 3) {
351
+ return `rgba(${rgbValues[0]}, ${rgbValues[1]}, ${rgbValues[2]}, ${opacity})`
352
+ }
353
+ }
354
+ // 如果已经是rgba或其他格式,直接返回带透明度的版本
355
+ return color.replace(/rgb\(/, 'rgba(').replace(/\)/, `, ${opacity})`)
356
+ }
357
+
358
+ // 生成渐变色字符串
359
+ const startColor = color.startsWith('rgba') ? color : toRgba(color, startOpacity)
360
+ const endColor = toRgba(color, endOpacity)
361
+
362
+ return `linear-gradient(${angle}deg, ${startColor} 0%, ${endColor} 100%)`
363
+ }
364
+
365
+ // 使用示例
366
+ // console.log(generateGradientColor('#2094FF'));
367
+ // 输出: linear-gradient(180deg, rgba(32,148,255,1) 0%, rgba(32,148,255,0.3) 100%)
368
+
369
+ // console.log(generateGradientColor('#2094FF', 90, 0.8, 0.1));
370
+ // 输出: linear-gradient(90deg, rgba(32,148,255,0.8) 0%, rgba(32,148,255,0.1) 100%)
371
+
372
+ /**
373
+ * 格式化日期显示
374
+ * @param date - 要格式化的日期,默认为当前日期
375
+ * @returns 格式化后的日期字符串,如"2025年9月25日 周四 下午"
376
+ */
377
+ export function formatChineseDate(date: Date = new Date()): string {
378
+ // 年份
379
+ const year = date.getFullYear()
380
+
381
+ // 月份(月份从0开始,需要+1)
382
+ const month = date.getMonth() + 1
383
+
384
+ // 日期
385
+ const day = date.getDate()
386
+
387
+ // 星期几
388
+ const weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
389
+ const weekday = weekdays[date.getDay()]
390
+
391
+ // 上午/下午判断
392
+ const hour = date.getHours()
393
+ const period = hour < 12 ? '上午' : '下午'
394
+
395
+ return `${year}年${month}月${day}日 ${weekday} ${period}`
396
+ }
397
+
398
+ // 使用示例
399
+ // console.log(formatChineseDate(new Date(2025, 8, 25)));
400
+ // 输出: 2025年9月25日 周四 下午
401
+
402
+ // console.log(formatChineseDate(new Date(2025, 8, 25, 10, 30)));
403
+ // 输出: 2025年9月25日 周四 上午
404
+
405
+ // console.log(formatChineseDate());
406
+ // 输出当前日期的格式化结果