首次提交:初始化项目代码
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
growthModalVisible: false,
|
||||
growthModalTitle: '',
|
||||
growthModalMessage: '',
|
||||
growthModalIcon: '',
|
||||
growthModalConfirmText: '太棒了!',
|
||||
growthModalCallback: null
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
showGrowthModal(growth) {
|
||||
this.showGrowthModalWithCallback(growth, null)
|
||||
},
|
||||
showGrowthModalWithCallback(growth, callback) {
|
||||
this.growthModalCallback = callback
|
||||
if (growth.levelUp) {
|
||||
const privilegesText = growth.newPrivileges && growth.newPrivileges.length
|
||||
? '\n解锁特权:' + growth.newPrivileges.join('、')
|
||||
: ''
|
||||
this.growthModalTitle = '🎉 恭喜升级!'
|
||||
this.growthModalMessage = `等级:Lv.${growth.oldLevel || growth.currentLevel - 1} → Lv.${growth.currentLevel}\n称号:${growth.levelTitle || '暂无'}\n获得经验:+${growth.expGained || 0} EXP${privilegesText}`
|
||||
this.growthModalIcon = '🎉'
|
||||
this.growthModalConfirmText = '太棒了!'
|
||||
this.growthModalVisible = true
|
||||
} else if (growth.newAchievements && growth.newAchievements.length > 0) {
|
||||
const ach = growth.newAchievements[0]
|
||||
this.growthModalTitle = '🏆 获得成就!'
|
||||
this.growthModalMessage = `${ach.name || ''}\n${ach.description || ''}\n稀有度:${ach.rarityName || '初级'}\n获得经验:+${ach.expReward || 0} EXP`
|
||||
this.growthModalIcon = ach.icon || '🏆'
|
||||
this.growthModalConfirmText = '太棒了!'
|
||||
this.growthModalVisible = true
|
||||
} else {
|
||||
if (typeof callback === 'function') {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
},
|
||||
onGrowthModalClose() {
|
||||
this.growthModalVisible = false
|
||||
if (typeof this.growthModalCallback === 'function') {
|
||||
this.growthModalCallback()
|
||||
this.growthModalCallback = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import { getMoodList } from '@/api'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
moodList: [],
|
||||
moodPage: 1,
|
||||
moodPageSize: 20,
|
||||
moodTotal: 0,
|
||||
moodLoading: false,
|
||||
moodHasMore: true
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async loadMoodList(params = {}) {
|
||||
if (this.moodLoading) return
|
||||
this.moodLoading = true
|
||||
try {
|
||||
const res = await getMoodList({
|
||||
page: this.moodPage,
|
||||
pageSize: this.moodPageSize,
|
||||
...params
|
||||
})
|
||||
const list = res?.list || res?.data || []
|
||||
this.moodTotal = res?.total || list.length
|
||||
if (this.moodPage === 1) {
|
||||
this.moodList = list
|
||||
} else {
|
||||
this.moodList = [...this.moodList, ...list]
|
||||
}
|
||||
this.moodHasMore = this.moodList.length < this.moodTotal
|
||||
return list
|
||||
} catch (e) {
|
||||
console.error('加载心情列表失败:', e)
|
||||
return []
|
||||
} finally {
|
||||
this.moodLoading = false
|
||||
}
|
||||
},
|
||||
async refreshMoodList(params = {}) {
|
||||
this.moodPage = 1
|
||||
this.moodHasMore = true
|
||||
return this.loadMoodList(params)
|
||||
},
|
||||
async loadMoreMood(params = {}) {
|
||||
if (!this.moodHasMore || this.moodLoading) return
|
||||
this.moodPage++
|
||||
return this.loadMoodList(params)
|
||||
},
|
||||
resetMoodList() {
|
||||
this.moodList = []
|
||||
this.moodPage = 1
|
||||
this.moodTotal = 0
|
||||
this.moodHasMore = true
|
||||
},
|
||||
removeMoodItem(id) {
|
||||
this.moodList = this.moodList.filter(item => item.id !== id)
|
||||
this.moodTotal = Math.max(0, this.moodTotal - 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
// mixins/themeMixin.js(Vue3 适配版)
|
||||
import {
|
||||
getThemeConfigFromStorage,
|
||||
THEME_CHANGE_EVENT,
|
||||
THEME_PRESETS,
|
||||
DEFAULT_THEME_KEY
|
||||
} from '../utils/theme.js' // 注意路径:Vue3 中 @ 别名需确认,这里先用相对路径
|
||||
|
||||
export default {
|
||||
// Vue3 中 data 需为函数(和Vue2一致,无需改)
|
||||
data() {
|
||||
return {
|
||||
themeConfig: getThemeConfigFromStorage()
|
||||
}
|
||||
},
|
||||
|
||||
// Vue3 计算属性写法不变
|
||||
computed: {
|
||||
pageThemeStyle() {
|
||||
return {
|
||||
backgroundColor: this.themeConfig.bgColor,
|
||||
color: this.themeConfig.textPrimary,
|
||||
minHeight: '100vh'
|
||||
}
|
||||
},
|
||||
cardThemeStyle() {
|
||||
return {
|
||||
backgroundColor: this.themeConfig.cardBgColor,
|
||||
borderColor: this.themeConfig.borderColor,
|
||||
boxShadow: `0 6rpx 20rpx ${this.themeConfig.shadowColor}`,
|
||||
borderRadius: '28rpx'
|
||||
}
|
||||
},
|
||||
btnPrimaryStyle() {
|
||||
return {
|
||||
backgroundColor: this.themeConfig.primaryColor,
|
||||
color: '#ffffff',
|
||||
border: 'none',
|
||||
borderRadius: '14rpx'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// ==================== 关键:Vue3 生命周期适配 ====================
|
||||
// 小程序中 Vue3 仍支持 onLoad/onShow/onUnload 等原生生命周期
|
||||
onLoad() {
|
||||
this.syncThemeConfig()
|
||||
this.watchThemeChange()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.syncThemeConfig()
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
// 移除监听,避免内存泄漏
|
||||
uni.$off(THEME_CHANGE_EVENT, this.themeChangeHandler)
|
||||
},
|
||||
|
||||
// 方法部分(和Vue2逻辑一致,无需改)
|
||||
methods: {
|
||||
/**
|
||||
* 同步最新主题配置(优先级:全局 > 本地 > 默认)
|
||||
*/
|
||||
syncThemeConfig() {
|
||||
const appInstance = getApp({ allowDefault: true })
|
||||
const globalTheme = appInstance?.globalData?.themeConfig
|
||||
|
||||
this.themeConfig = globalTheme
|
||||
|| getThemeConfigFromStorage()
|
||||
|| THEME_PRESETS[DEFAULT_THEME_KEY]
|
||||
},
|
||||
|
||||
/**
|
||||
* 监听全局主题变更事件
|
||||
*/
|
||||
watchThemeChange() {
|
||||
this.themeChangeHandler = ({ key, config }) => {
|
||||
if (key && config) {
|
||||
this.themeConfig = config
|
||||
// 可选:页面自定义主题更新逻辑
|
||||
this.onThemeUpdated && this.onThemeUpdated()
|
||||
}
|
||||
}
|
||||
uni.$on(THEME_CHANGE_EVENT, this.themeChangeHandler)
|
||||
},
|
||||
|
||||
/**
|
||||
* 【可选】页面自定义主题更新逻辑(供页面重写)
|
||||
*/
|
||||
onThemeUpdated() {
|
||||
// 空实现
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user