完成支付宝分包

This commit is contained in:
tangxinyue 2026-01-15 18:42:49 +08:00
parent f44238d9bc
commit bcb487daab
8 changed files with 190 additions and 138 deletions

16
App.vue
View File

@ -4,7 +4,21 @@ export default {
const startTime = Date.now() const startTime = Date.now()
console.log('App Launch', options) console.log('App Launch', options)
// 1. // 1.
const systemInfo = uni.getSystemInfoSync()
uni.setStorageSync('systemInfo', {
platform: systemInfo.platform,
system: systemInfo.system,
osName: systemInfo.osName,
osVersion: systemInfo.osVersion,
statusBarHeight: systemInfo.statusBarHeight,
windowWidth: systemInfo.windowWidth,
windowHeight: systemInfo.windowHeight,
isIOS: systemInfo.platform === 'ios',
isAndroid: systemInfo.platform === 'android'
})
// 2.
this.initConfig(options) this.initConfig(options)
// //

View File

@ -83,10 +83,7 @@
import { import {
reactive, reactive,
toRefs, toRefs,
ref, ref
defineExpose,
defineProps,
defineEmits
} from 'vue' } from 'vue'
import addBillJson from '@/static/json/add-bill.json' import addBillJson from '@/static/json/add-bill.json'

View File

@ -20,15 +20,11 @@ export function createApp() {
// 将store挂载到全局 // 将store挂载到全局
app.config.globalProperties.$store = store app.config.globalProperties.$store = store
// 获取系统信息并挂载到全局 // 从缓存读取系统信息已在App.vue中获取
const systemInfo = uni.getSystemInfoSync() const systemInfo = uni.getStorageSync('systemInfo') || {}
app.config.globalProperties.$platform = systemInfo.platform app.config.globalProperties.$platform = systemInfo.platform
app.config.globalProperties.$systemInfo = systemInfo app.config.globalProperties.$systemInfo = systemInfo
// 获取系统信息
const { getSystemInfo } = useStore()
getSystemInfo()
return { return {
app app
} }

View File

@ -16,6 +16,10 @@
"autoclose": true, "autoclose": true,
"delay": 0 "delay": 0
}, },
"optimization": {
"subPackages": true
},
"runmode": "liberate", //
/* */ /* */
"modules": { "modules": {
"Camera": {} "Camera": {}

View File

@ -7,9 +7,14 @@
"navigationBarTitleText": "uni-app", "navigationBarTitleText": "uni-app",
"navigationStyle": "custom" "navigationStyle": "custom"
} }
}, }
],
"subPackages": [
{ {
"path": "pages/balance/index", "root": "pages/balance",
"pages": [
{
"path": "index",
"style": { "style": {
"navigationBarTitleText": "余额页面", "navigationBarTitleText": "余额页面",
"navigationStyle": "custom", "navigationStyle": "custom",
@ -17,55 +22,77 @@
} }
}, },
{ {
"path": "pages/bill/bill-list/bill-list", "path": "fast-entrance-management/fast-entrance-management",
"style": {
"navigationBarTitleText": "快速入口页面",
"navigationStyle": "custom"
}
}
]
},
{
"root": "pages/bill",
"pages": [
{
"path": "bill-list/bill-list",
"style": { "style": {
"navigationBarTitleText": "账单列表页面", "navigationBarTitleText": "账单列表页面",
"navigationStyle": "custom" "navigationStyle": "custom"
} }
}, },
{ {
"path": "pages/bill/add-bill/add-bill", "path": "add-bill/add-bill",
"style": { "style": {
"navigationBarTitleText": "新增账单", "navigationBarTitleText": "新增账单",
"navigationStyle": "custom" "navigationStyle": "custom"
} }
}, },
{ {
"path": "pages/common/hot-icon/hot-icon", "path": "bill-detail/bill-detail",
"style": {
"navigationBarTitleText": "账单详情页",
"navigationStyle": "custom"
}
}
]
},
{
"root": "pages/common",
"pages": [
{
"path": "hot-icon/hot-icon",
"style": { "style": {
"navigationBarTitleText": "热门图标", "navigationBarTitleText": "热门图标",
"navigationStyle": "custom" "navigationStyle": "custom"
} }
}, },
{ {
"path": "pages/balance/fast-entrance-management/fast-entrance-management", "path": "webview/webview",
"style": {
"navigationBarTitleText": "快速入口页面",
"navigationStyle": "custom"
}
},
{
"path": "pages/bill/bill-detail/bill-detail",
"style": {
"navigationBarTitleText": "账单详情页",
"navigationStyle": "custom"
}
},
{
"path": "pages/index/alipay-annual-bill/alipay-annual-bill",
"style": {
"navigationBarTitleText": "支付宝年度账单",
"navigationStyle": "custom"
}
},
{
"path": "pages/common/webview/webview",
"style": { "style": {
"navigationBarTitleText": "webView页面", "navigationBarTitleText": "webView页面",
"navigationStyle": "custom" "navigationStyle": "custom"
} }
},
{
"path": "alipay-annual-bill/alipay-annual-bill",
"style": {
"navigationBarTitleText": "支付宝年度账单",
"navigationStyle": "custom"
}
}
]
} }
], ],
"preloadRule": {
"pages/index/index": {
"network": "all",
"packages": [
"pages/balance",
"pages/bill",
"pages/common"
]
}
},
"globalStyle": { "globalStyle": {
"navigationBarTextStyle": "black", "navigationBarTextStyle": "black",
"navigationBarTitleText": "uni-app", "navigationBarTitleText": "uni-app",

View File

@ -70,8 +70,7 @@
<view class="group-box"> <view class="group-box">
<image class="title-img" src="/static/image/index/monixiaobao.png"></image> <image class="title-img" src="/static/image/index/monixiaobao.png"></image>
<view class="menu-box"> <view class="menu-box">
<view class="item-box" v-for="item in menuList" :key="item.name" <view class="item-box" v-for="item in menuList" :key="item.name" @click="clickMenu(item)">
@click="util.goPage(item.path)">
<view class="menu-item" :style="{ width: (windowWidth - 50) / 2 + 'px' }"> <view class="menu-item" :style="{ width: (windowWidth - 50) / 2 + 'px' }">
<!-- <text class="menu-item-name">{{ item.name }}</text> --> <!-- <text class="menu-item-name">{{ item.name }}</text> -->
<image class="name-img" :src="'/static/image/index/menu-name/' + item.icon + '.png'" <image class="name-img" :src="'/static/image/index/menu-name/' + item.icon + '.png'"
@ -88,7 +87,7 @@
<view class="activity-box"> <view class="activity-box">
<image class="alipay-year-bill" :style="{ width: (windowWidth - 32) + 'px' }" <image class="alipay-year-bill" :style="{ width: (windowWidth - 32) + 'px' }"
src="/static/image/index/alipay-year-bill.png" mode="widthFix" src="/static/image/index/alipay-year-bill.png" mode="widthFix"
@click="util.goPage(`/pages/index/alipay-annual-bill/alipay-annual-bill`)"></image> @click="util.goPage(`/pages/common/alipay-annual-bill/alipay-annual-bill`)"></image>
</view> </view>
</view> </view>
@ -103,7 +102,7 @@
<script setup> <script setup>
import { import {
util, util,
deviceUtil uiUtil
} from '@/utils/common.js' } from '@/utils/common.js'
import { import {
storage storage
@ -285,6 +284,14 @@ const setUserData = () => {
} }
} }
const clickMenu = (item) => {
if (!item.path) {
uiUtil.showError('开发中')
} else {
util.goPage(item.path)
}
}
/** /**
* 点击视频教程 * 点击视频教程
* @param item * @param item
@ -685,10 +692,6 @@ const runMarqueeAnimation = (containerWidth, textWidth, myId) => {
margin: 0 32rpx; margin: 0 32rpx;
} }
.alipay-year-bill {
/* width: 100%; */
}
.footer-box { .footer-box {
display: flex; display: flex;
align-items: center; align-items: center;

View File

@ -3,6 +3,17 @@ import { storage } from '../utils/storage';
// 防抖函数
const debounce = (fn, delay = 300) => {
let timer = null
return function (...args) {
if (timer) clearTimeout(timer)
timer = setTimeout(() => {
fn.apply(this, args)
}, delay)
}
}
// 定义应用的全局状态 // 定义应用的全局状态
export const store = reactive({ export const store = reactive({
// 用户信息 // 用户信息
@ -15,11 +26,12 @@ export const store = reactive({
notifications: true notifications: true
}, },
// 系统信息 // 系统信息(从缓存读取,避免重复调用)
systemInfo: { systemInfo: uni.getStorageSync('systemInfo') || {
statusBarHeight: 0, statusBarHeight: 0,
windowHeight: 0, windowHeight: 0,
windowWidth: 0 windowWidth: 0,
platform: ''
}, },
// 账单列表 // 账单列表
@ -71,8 +83,16 @@ export const useStore = () => {
return store.billList return store.billList
} }
// 数据持久化 // 手动保存账单列表(替代自动监听)
// 监听store变化自动保存到本地存储 const saveBillList = debounce(() => {
storage.set('bill_list', store.billList)
}, 500)
// 优化后的监听:使用防抖减少存储频率
const debouncedSaveSettings = debounce((newValue) => {
storage.set('settings', newValue)
}, 500)
watch( watch(
() => store.userInfo, () => store.userInfo,
(newValue) => storage.set('userInfo', newValue), (newValue) => storage.set('userInfo', newValue),
@ -81,28 +101,18 @@ export const useStore = () => {
watch( watch(
() => store.settings, () => store.settings,
(newValue) => storage.set('settings', newValue), (newValue) => debouncedSaveSettings(newValue),
{ deep: true } { deep: true }
); );
watch( // 移除billList的自动监听改为手动调用saveBillList
() => store.billList,
(newValue) => storage.set('bill_list', newValue),
{ deep: true }
);
// 获取系统信息 // 获取系统信息(从缓存读取)
const getSystemInfo = () => { const getSystemInfo = () => {
uni.getSystemInfo({ const cachedInfo = uni.getStorageSync('systemInfo')
success: (res) => { if (cachedInfo) {
store.systemInfo.statusBarHeight = res.statusBarHeight || 0; store.systemInfo = cachedInfo
store.systemInfo.windowHeight = res.windowHeight || 0;
store.systemInfo.windowWidth = res.windowWidth || 0;
},
fail: (err) => {
console.error('获取系统信息失败:', err);
} }
});
}; };
return { return {
@ -114,6 +124,7 @@ export const useStore = () => {
updateBill, updateBill,
deleteBill, deleteBill,
getBillList, getBillList,
saveBillList,
getSystemInfo getSystemInfo
}; };
}; };