Skip to content

Commit 6cff528

Browse files
committed
chore(deps): upgrade
1 parent c279bf1 commit 6cff528

File tree

6 files changed

+309
-561
lines changed

6 files changed

+309
-561
lines changed
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
// app.ts
2-
App<IAppOption>({
1+
import { createApp, onLaunch } from 'wevu'
2+
3+
createApp({
34
globalData: {},
4-
onLaunch() {
5-
// 展示本地存储能力
6-
const logs = wx.getStorageSync('logs') || []
7-
logs.unshift(Date.now())
8-
wx.setStorageSync('logs', logs)
5+
setup() {
6+
onLaunch(() => {
7+
const logs: number[] = wx.getStorageSync('logs') || []
8+
logs.unshift(Date.now())
9+
wx.setStorageSync('logs', logs)
910

10-
// 登录
11-
wx.login({
12-
success: (res) => {
13-
console.log(res.code)
14-
// 发送 res.code 到后台换取 openId, sessionKey, unionId
15-
},
11+
wx.login({
12+
success: (res) => {
13+
console.log(res.code)
14+
},
15+
})
1616
})
1717
},
1818
})
Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
type TrendPoint = number
1+
import { defineComponent, onMounted, onUnmounted, ref, watch } from 'wevu'
22

3-
interface SkylineNavbarInstance extends WechatMiniprogram.Component.TrivialInstance {
4-
__timer?: number
5-
}
3+
type TrendPoint = number
64

75
const defaultTrend: TrendPoint[] = [42, 68, 54, 92, 78, 118, 88]
86

@@ -13,7 +11,7 @@ function formatTime() {
1311
return `${hours}:${minutes}`
1412
}
1513

16-
Component({
14+
export default defineComponent({
1715
options: {
1816
addGlobalClass: true,
1917
},
@@ -35,61 +33,59 @@ Component({
3533
value: defaultTrend,
3634
},
3735
},
38-
data: {
39-
currentTime: formatTime(),
40-
trendBars: [] as Array<{ height: number, label: string }>,
41-
},
42-
lifetimes: {
43-
attached() {
44-
this.updateTime()
45-
this.updateTrend(this.properties.trend as TrendPoint[])
46-
;(this as SkylineNavbarInstance).__timer = setInterval(() => {
47-
this.updateTime()
48-
}, 60000) as unknown as number
49-
},
50-
detached() {
51-
const instance = this as SkylineNavbarInstance
52-
if (typeof instance.__timer === 'number') {
53-
clearInterval(instance.__timer)
54-
delete instance.__timer
55-
}
56-
},
57-
},
58-
observers: {
59-
trend(value: TrendPoint[]) {
60-
this.updateTrend(value)
61-
},
62-
},
63-
methods: {
64-
updateTime() {
65-
this.setData({
66-
currentTime: formatTime(),
67-
})
68-
},
69-
updateTrend(trend: TrendPoint[]) {
36+
setup(props, ctx) {
37+
const currentTime = ref(formatTime())
38+
const trendBars = ref<Array<{ height: number, label: string }>>([])
39+
40+
let timer: number | undefined
41+
42+
function updateTime() {
43+
currentTime.value = formatTime()
44+
}
45+
46+
function updateTrend(trend: TrendPoint[]) {
7047
if (!Array.isArray(trend) || trend.length === 0) {
71-
this.setData({ trendBars: [] })
48+
trendBars.value = []
7249
return
7350
}
7451

7552
const max = Math.max(...trend)
7653
const min = Math.min(...trend)
7754
const range = Math.max(max - min, 1)
7855

79-
const normalized = trend.map((value, index) => {
56+
trendBars.value = trend.map((value, index) => {
8057
const height = Math.round(((value - min) / range) * 55 + 45)
8158
return {
8259
height,
8360
label: `T${index + 1}`,
8461
}
8562
})
63+
}
8664

87-
this.setData({
88-
trendBars: normalized,
89-
})
90-
},
91-
handlePrimaryTap() {
92-
this.triggerEvent('primarytap')
93-
},
65+
watch(
66+
() => props.trend as TrendPoint[],
67+
(value) => updateTrend(value),
68+
{ immediate: true, deep: true },
69+
)
70+
71+
onMounted(() => {
72+
updateTime()
73+
timer = setInterval(updateTime, 60000)
74+
})
75+
76+
onUnmounted(() => {
77+
if (timer != null) clearInterval(timer)
78+
timer = undefined
79+
})
80+
81+
function handlePrimaryTap() {
82+
ctx.emit('primarytap')
83+
}
84+
85+
return {
86+
currentTime,
87+
trendBars,
88+
handlePrimaryTap,
89+
}
9490
},
9591
})
Lines changed: 65 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,85 @@
1-
// index.ts
2-
// 获取应用实例
1+
import { defineComponent, reactive, ref } from 'wevu'
32

4-
Component({
5-
data: {
6-
motto: 'Hello World',
7-
userInfo: {
3+
const defaultAvatarUrl =
4+
'https://mmbiz.qpic.cn/mmbiz/vi_32/Q0j4TwGTfTJLTpJ5dD6Y3vR0pu2Lx5D3w1lUwLrZ7NCyKz1q8I4xA86c1k3apwFVB9C7bPBCn2iYg4JibL0z0icA/0'
5+
6+
interface UserInfo {
7+
nickName: string
8+
avatarUrl: string
9+
}
10+
11+
export default defineComponent({
12+
setup() {
13+
const motto = ref('Hello World')
14+
const userInfo = reactive<UserInfo>({
815
nickName: '',
9-
},
10-
hasUserInfo: false,
11-
canIUseGetUserProfile: wx.canIUse('getUserProfile'),
12-
canIUseNicknameComp: wx.canIUse('input.type.nickname'),
13-
skylineNav: {
16+
avatarUrl: defaultAvatarUrl,
17+
})
18+
const hasUserInfo = ref(false)
19+
const canIUseGetUserProfile = wx.canIUse('getUserProfile')
20+
const canIUseNicknameComp = wx.canIUse('input.type.nickname')
21+
const skylineNav = reactive({
1422
title: 'Skyline Market',
1523
location: '深圳 · 夜景塔群',
1624
weather: '晴 · 26°C',
17-
trend: [48, 76, 58, 102, 96, 132, 118],
18-
},
19-
},
20-
methods: {
21-
// 事件处理函数
22-
bindViewTap() {
25+
trend: [48, 76, 58, 102, 96, 132, 118] as number[],
26+
})
27+
28+
function syncHasUserInfo() {
29+
hasUserInfo.value = Boolean(
30+
userInfo.nickName
31+
&& userInfo.avatarUrl
32+
&& userInfo.avatarUrl !== defaultAvatarUrl,
33+
)
34+
}
35+
36+
function bindViewTap() {
2337
wx.navigateTo({
2438
url: '../logs/logs',
2539
})
26-
},
27-
onChooseAvatar(e: any) {
40+
}
41+
42+
function onChooseAvatar(e: any) {
2843
const { avatarUrl } = e.detail
29-
const { nickName } = this.data.userInfo
30-
this.setData({
31-
'userInfo.avatarUrl': avatarUrl,
32-
'hasUserInfo': nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
33-
})
34-
},
35-
onInputChange(e: any) {
36-
const nickName = e.detail.value
37-
const { avatarUrl } = this.data.userInfo
38-
this.setData({
39-
'userInfo.nickName': nickName,
40-
'hasUserInfo': nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
41-
})
42-
},
43-
handleNavAction() {
44+
userInfo.avatarUrl = avatarUrl
45+
syncHasUserInfo()
46+
}
47+
48+
function onInputChange(e: any) {
49+
userInfo.nickName = e.detail.value
50+
syncHasUserInfo()
51+
}
52+
53+
function handleNavAction() {
4454
wx.showToast({
4555
title: '更多趋势即将上线',
4656
icon: 'none',
4757
})
48-
},
49-
getUserProfile() {
50-
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
58+
}
59+
60+
function getUserProfile() {
5161
wx.getUserProfile({
52-
desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
62+
desc: '展示用户信息',
5363
success: (res) => {
5464
console.log(res)
55-
this.setData({
56-
userInfo: res.userInfo,
57-
hasUserInfo: true,
58-
})
65+
Object.assign(userInfo, res.userInfo)
66+
syncHasUserInfo()
5967
},
6068
})
61-
},
69+
}
70+
71+
return {
72+
motto,
73+
userInfo,
74+
hasUserInfo,
75+
canIUseGetUserProfile,
76+
canIUseNicknameComp,
77+
skylineNav,
78+
bindViewTap,
79+
onChooseAvatar,
80+
onInputChange,
81+
handleNavAction,
82+
getUserProfile,
83+
}
6284
},
6385
})

apps/vite-native-ts-skyline/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
"build-npm": "weapp-vite build-npm",
2424
"postinstall": "weapp-tw patch"
2525
},
26+
"dependencies": {
27+
"wevu": "^1.0.1"
28+
},
2629
"devDependencies": {
2730
"@egoist/tailwindcss-icons": "^1.9.0",
2831
"@iconify-json/mdi": "^1.2.3",

0 commit comments

Comments
 (0)