添加首页
This commit is contained in:
@@ -11,7 +11,12 @@ const STORAGE_KEY = 'app_launch_payment_data'
|
|||||||
const APP_QUERY_KEY = 'app_query_params'
|
const APP_QUERY_KEY = 'app_query_params'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析查询字符串为对象
|
* 需要转为数组的参数字段(逗号分隔字符串 → 数组)
|
||||||
|
*/
|
||||||
|
const ARRAY_PARAMS = ['billIds']
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析查询字符串为对象,数组字段自动拆分
|
||||||
*/
|
*/
|
||||||
function parseQueryString(str) {
|
function parseQueryString(str) {
|
||||||
if (!str || typeof str !== 'string') return null
|
if (!str || typeof str !== 'string') return null
|
||||||
@@ -21,11 +26,47 @@ function parseQueryString(str) {
|
|||||||
if (idx === -1) return
|
if (idx === -1) return
|
||||||
const key = item.substring(0, idx)
|
const key = item.substring(0, idx)
|
||||||
const val = item.substring(idx + 1)
|
const val = item.substring(idx + 1)
|
||||||
params[key] = decodeURIComponent(val || '')
|
const decoded = decodeURIComponent(val || '')
|
||||||
|
// 同名参数合并为数组;已知数组字段按逗号拆分
|
||||||
|
if (key in params) {
|
||||||
|
if (Array.isArray(params[key])) {
|
||||||
|
params[key].push(decoded)
|
||||||
|
} else {
|
||||||
|
params[key] = [params[key], decoded]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
params[key] = ARRAY_PARAMS.includes(key) && decoded.includes(',')
|
||||||
|
? decoded.split(',').map(v => v.trim()).filter(Boolean)
|
||||||
|
: decoded
|
||||||
|
}
|
||||||
})
|
})
|
||||||
return params
|
return params
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 归一化 billId/billIds:单个 id 用 billId,多个用 billIds,统一转为 billIds 数组
|
||||||
|
*/
|
||||||
|
function normalizeBillParams(obj) {
|
||||||
|
if (!obj) return
|
||||||
|
// 先解码再拆分为数组
|
||||||
|
if (typeof obj.billIds === 'string') {
|
||||||
|
const decoded = decodeURIComponent(obj.billIds)
|
||||||
|
obj.billIds = decoded.includes(',')
|
||||||
|
? decoded.split(',').map(v => v.trim()).filter(Boolean)
|
||||||
|
: [decoded]
|
||||||
|
}
|
||||||
|
// billId 存在且 billIds 不存在时,包装为数组
|
||||||
|
if (obj.billId && !obj.billIds) {
|
||||||
|
const decoded = decodeURIComponent(
|
||||||
|
typeof obj.billId === 'string' ? obj.billId : String(obj.billId)
|
||||||
|
)
|
||||||
|
obj.billIds = decoded.includes(',')
|
||||||
|
? decoded.split(',').map(v => v.trim()).filter(Boolean)
|
||||||
|
: [decoded]
|
||||||
|
delete obj.billId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从启动参数中获取 App 传入的全部数据(支付参数 + token + userId)
|
* 从启动参数中获取 App 传入的全部数据(支付参数 + token + userId)
|
||||||
*/
|
*/
|
||||||
@@ -71,7 +112,10 @@ export function captureAppLaunchData(onShowOptions) {
|
|||||||
data = tryGetData(onShowOptions, '热启动')
|
data = tryGetData(onShowOptions, '热启动')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data && (data.payAmount || data.acct || data.custId || data.billId)) {
|
if (data && (data.payAmount || data.acct || data.custId || data.billId || data.billIds)) {
|
||||||
|
// 归一化 billId/billIds:单个 id 用 billId,多个用 billIds,统一转为 billIds 数组
|
||||||
|
normalizeBillParams(data)
|
||||||
|
|
||||||
// 恢复登录态
|
// 恢复登录态
|
||||||
if (data.token) {
|
if (data.token) {
|
||||||
uni.setStorageSync('token', data.token)
|
uni.setStorageSync('token', data.token)
|
||||||
@@ -86,6 +130,9 @@ export function captureAppLaunchData(onShowOptions) {
|
|||||||
console.log('已存储 App 支付数据:', JSON.stringify(data))
|
console.log('已存储 App 支付数据:', JSON.stringify(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 归一化 queryData 中的 billId/billIds
|
||||||
|
normalizeBillParams(queryData)
|
||||||
|
|
||||||
// 单独保存参数供接口使用(优先 queryData,fallback 到 data,即 extraData 来源)
|
// 单独保存参数供接口使用(优先 queryData,fallback 到 data,即 extraData 来源)
|
||||||
const queryParams = queryData || data
|
const queryParams = queryData || data
|
||||||
if (queryParams) {
|
if (queryParams) {
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ const handleCancel = () => {
|
|||||||
if (pages.length > 1) {
|
if (pages.length > 1) {
|
||||||
uni.navigateBack();
|
uni.navigateBack();
|
||||||
} else {
|
} else {
|
||||||
uni.redirectTo({ url: '/pages/arrearsPayment/arrearsPayment' });
|
uni.redirectTo({ url: '/pages/index/index' });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -204,7 +204,7 @@ const handleLogin = () => {
|
|||||||
// 登录成功后返回来源页
|
// 登录成功后返回来源页
|
||||||
uni.navigateBack({
|
uni.navigateBack({
|
||||||
fail: () => {
|
fail: () => {
|
||||||
uni.redirectTo({ url: '/pages/arrearsPayment/arrearsPayment' });
|
uni.redirectTo({ url: '/pages/index/index' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},1500)
|
},1500)
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ const handleCancel = () => {
|
|||||||
if (pages.length > 1) {
|
if (pages.length > 1) {
|
||||||
uni.navigateBack();
|
uni.navigateBack();
|
||||||
} else {
|
} else {
|
||||||
uni.redirectTo({ url: '/pages/arrearsPayment/arrearsPayment' });
|
uni.redirectTo({ url: '/pages/index/index' });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ const handleLogin = () => {
|
|||||||
// 登录成功后返回来源页
|
// 登录成功后返回来源页
|
||||||
uni.navigateBack({
|
uni.navigateBack({
|
||||||
fail: () => {
|
fail: () => {
|
||||||
uni.redirectTo({ url: '/pages/arrearsPayment/arrearsPayment' });
|
uni.redirectTo({ url: '/pages/index/index' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},1000)
|
},1000)
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
{
|
{
|
||||||
"pages": [
|
"pages": [
|
||||||
|
{
|
||||||
|
"path": "pages/index/index",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "花开物业"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "pages/arrearsPayment/arrearsPayment",
|
"path": "pages/arrearsPayment/arrearsPayment",
|
||||||
"style": {
|
"style": {
|
||||||
@@ -53,53 +59,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"root": "pageSubPack/payment-list",
|
|
||||||
"pages": [
|
|
||||||
{
|
|
||||||
"path": "addPayment",
|
|
||||||
"style": {
|
|
||||||
"navigationBarTitleText": "",
|
|
||||||
"navigationStyle": "custom"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "addPaymentSuccess",
|
|
||||||
"style": {
|
|
||||||
"navigationBarTitleText": "",
|
|
||||||
"navigationStyle": "custom"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "noArrearsPayment",
|
|
||||||
"style": {
|
|
||||||
"navigationBarTitleText": "",
|
|
||||||
"navigationStyle": "custom"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "paymentRecord",
|
|
||||||
"style": {
|
|
||||||
"navigationBarTitleText": "",
|
|
||||||
"navigationStyle": "custom"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "selectPaymentEntity",
|
|
||||||
"style": {
|
|
||||||
"navigationBarTitleText": "",
|
|
||||||
"navigationStyle": "custom"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "addHydropower",
|
|
||||||
"style": {
|
|
||||||
"navigationBarTitleText": "",
|
|
||||||
"navigationStyle": "custom"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"easycom": {
|
"easycom": {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ onShow(() => {
|
|||||||
const loadPaymentItem = () => {
|
const loadPaymentItem = () => {
|
||||||
const appData = getAppPaymentData()
|
const appData = getAppPaymentData()
|
||||||
if (appData) {
|
if (appData) {
|
||||||
console.log('检测到 App 跳转参数:', appData)
|
console.log('-----检测到 App 跳转参数:', appData)
|
||||||
clearAppPaymentData()
|
clearAppPaymentData()
|
||||||
const item = buildPaymentItemFromApp(appData)
|
const item = buildPaymentItemFromApp(appData)
|
||||||
uni.setStorageSync('arrearsPayment', item)
|
uni.setStorageSync('arrearsPayment', item)
|
||||||
@@ -65,7 +65,8 @@ const handlePay = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
delete apiParams.token
|
delete apiParams.token
|
||||||
|
delete apiParams.billId // billId 已归一化为 billIds 数组,删除冗余字段
|
||||||
|
console.log('-----传递小程序参数2222------:', apiParams)
|
||||||
uni.showLoading({ title: '加载中...', mask: true })
|
uni.showLoading({ title: '加载中...', mask: true })
|
||||||
try {
|
try {
|
||||||
const res = await getBankMiniProgramParams(apiParams)
|
const res = await getBankMiniProgramParams(apiParams)
|
||||||
|
|||||||
212
huakai-app/pages/index/index.vue
Normal file
212
huakai-app/pages/index/index.vue
Normal file
@@ -0,0 +1,212 @@
|
|||||||
|
<template>
|
||||||
|
<view class="home">
|
||||||
|
<!-- 顶部品牌区 -->
|
||||||
|
<view class="header">
|
||||||
|
<view class="app-name">花开物业</view>
|
||||||
|
<view class="app-slogan">物业缴费服务</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 未登录:登录引导 -->
|
||||||
|
<view v-if="!logged" class="guest">
|
||||||
|
<view class="guest-card">
|
||||||
|
<view class="guest-title">欢迎使用花开物业</view>
|
||||||
|
<view class="guest-tip">登录后可查询缴费记录、在线缴纳</view>
|
||||||
|
<button class="primary-btn" @click="goLogin">登录 / 注册</button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 已登录:缴费记录 -->
|
||||||
|
<view v-else class="member">
|
||||||
|
<view class="section-head">
|
||||||
|
<text class="section-title">缴费记录</text>
|
||||||
|
<text class="section-sub" v-if="records.length">共 {{ records.length }} 条</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view v-if="loading" class="empty">加载中...</view>
|
||||||
|
<view v-else-if="records.length === 0" class="empty">暂无缴费记录</view>
|
||||||
|
<view v-else class="record-list">
|
||||||
|
<view v-for="(r, i) in records" :key="i" class="record-item">
|
||||||
|
<view class="record-left">
|
||||||
|
<text class="record-type">{{ r.type }}</text>
|
||||||
|
<text class="record-time">{{ r.time }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="record-right">
|
||||||
|
<text class="record-amount">{{ r.amount }}</text>
|
||||||
|
<text class="record-status">{{ r.status }}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<button class="logout-btn" @click="logout">退出登录</button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import { onShow } from '@dcloudio/uni-app'
|
||||||
|
import { getTopupRecordWithStat } from '/pageSubPack/api/apiSub.js'
|
||||||
|
import { isLoggedIn, clearLoginState } from '/pageSubPack/api/auth.js'
|
||||||
|
import { getAppPaymentData } from '/pageSubPack/api/appLaunch.js'
|
||||||
|
|
||||||
|
const logged = ref(false)
|
||||||
|
const loading = ref(false)
|
||||||
|
const records = ref([])
|
||||||
|
|
||||||
|
onShow(() => {
|
||||||
|
// 从花开物业 App 跳转进入(带支付参数)→ 直接进入缴费页
|
||||||
|
if (getAppPaymentData()) {
|
||||||
|
uni.redirectTo({ url: '/pages/arrearsPayment/arrearsPayment' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
logged.value = isLoggedIn()
|
||||||
|
if (logged.value) {
|
||||||
|
loadRecords()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const goLogin = () => {
|
||||||
|
uni.navigateTo({ url: '/pageSubPack/loginSub/pwd-login' })
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadRecords = async () => {
|
||||||
|
const residentUserId = uni.getStorageSync('userId') || uni.getStorageSync('residentUserId')
|
||||||
|
if (!residentUserId) {
|
||||||
|
records.value = []
|
||||||
|
return
|
||||||
|
}
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const res = await getTopupRecordWithStat({ residentUserId, pageNum: 1, pageSize: 20 })
|
||||||
|
if (res.code === 200 && res.data) {
|
||||||
|
const list = res.data.list || res.data.records || res.data.rows || []
|
||||||
|
// 打印首条原始数据,便于核对后端返回字段
|
||||||
|
if (list.length) console.log('缴费记录示例:', JSON.stringify(list[0]))
|
||||||
|
records.value = list.map(normalizeRecord)
|
||||||
|
} else {
|
||||||
|
records.value = []
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('加载缴费记录失败:', err)
|
||||||
|
records.value = []
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 后端返回字段未明确,这里做防御性映射,字段名以实际接口为准
|
||||||
|
const normalizeRecord = (r) => ({
|
||||||
|
type: r.payType || r.type || r.goodName || r.feeName || '缴费',
|
||||||
|
time: r.createTime || r.payTime || r.updateTime || '',
|
||||||
|
amount: formatAmount(r.payAmount ?? r.amount ?? r.rechargeAmount ?? r.money),
|
||||||
|
status: formatStatus(r.status ?? r.payStatus)
|
||||||
|
})
|
||||||
|
|
||||||
|
const formatAmount = (v) => {
|
||||||
|
if (v === undefined || v === null || v === '') return ''
|
||||||
|
const n = Number(v)
|
||||||
|
return isNaN(n) ? String(v) : '¥' + n.toFixed(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatStatus = (s) => {
|
||||||
|
if (s === undefined || s === null || s === '') return ''
|
||||||
|
const map = { 0: '待支付', 1: '支付成功', 2: '支付失败' }
|
||||||
|
if (map[s] !== undefined) return map[s]
|
||||||
|
const str = String(s)
|
||||||
|
if (str === 'SUCCESS') return '支付成功'
|
||||||
|
if (str === 'FAIL') return '支付失败'
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
const logout = () => {
|
||||||
|
uni.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '确定退出登录吗?',
|
||||||
|
success: (res) => {
|
||||||
|
if (res.confirm) {
|
||||||
|
clearLoginState()
|
||||||
|
logged.value = false
|
||||||
|
records.value = []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
page { background-color: #f6f7fb; }
|
||||||
|
.home { min-height: 100vh; }
|
||||||
|
|
||||||
|
.header {
|
||||||
|
background: linear-gradient(180deg, #1677ff, #4c9aff);
|
||||||
|
padding: 120rpx 40rpx 60rpx;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.app-name { font-size: 44rpx; font-weight: 700; }
|
||||||
|
.app-slogan { font-size: 26rpx; opacity: 0.85; margin-top: 12rpx; }
|
||||||
|
|
||||||
|
.guest { padding: 40rpx; }
|
||||||
|
.guest-card {
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
padding: 60rpx 40rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
|
||||||
|
}
|
||||||
|
.guest-title { font-size: 34rpx; font-weight: 600; color: #222; }
|
||||||
|
.guest-tip { font-size: 26rpx; color: #888; margin: 20rpx 0 50rpx; text-align: center; }
|
||||||
|
.primary-btn {
|
||||||
|
width: 100%;
|
||||||
|
height: 88rpx;
|
||||||
|
line-height: 88rpx;
|
||||||
|
background: #1677ff;
|
||||||
|
color: #fff;
|
||||||
|
border-radius: 44rpx;
|
||||||
|
font-size: 30rpx;
|
||||||
|
}
|
||||||
|
.primary-btn::after { border: none; }
|
||||||
|
|
||||||
|
.member { padding: 32rpx 40rpx; }
|
||||||
|
.section-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 24rpx;
|
||||||
|
}
|
||||||
|
.section-title { font-size: 34rpx; font-weight: 600; color: #222; }
|
||||||
|
.section-sub { font-size: 24rpx; color: #999; }
|
||||||
|
|
||||||
|
.empty { text-align: center; color: #999; font-size: 28rpx; padding: 120rpx 0; }
|
||||||
|
|
||||||
|
.record-list { display: flex; flex-direction: column; gap: 20rpx; }
|
||||||
|
.record-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 16rpx;
|
||||||
|
padding: 28rpx 30rpx;
|
||||||
|
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
|
||||||
|
}
|
||||||
|
.record-left { display: flex; flex-direction: column; }
|
||||||
|
.record-type { font-size: 30rpx; color: #222; font-weight: 500; }
|
||||||
|
.record-time { font-size: 24rpx; color: #999; margin-top: 8rpx; }
|
||||||
|
.record-right { display: flex; flex-direction: column; align-items: flex-end; }
|
||||||
|
.record-amount { font-size: 32rpx; color: #1677ff; font-weight: 600; }
|
||||||
|
.record-status { font-size: 24rpx; color: #999; margin-top: 8rpx; }
|
||||||
|
|
||||||
|
.logout-btn {
|
||||||
|
margin-top: 60rpx;
|
||||||
|
width: 100%;
|
||||||
|
height: 88rpx;
|
||||||
|
line-height: 88rpx;
|
||||||
|
background: #fff;
|
||||||
|
color: #666;
|
||||||
|
border-radius: 44rpx;
|
||||||
|
font-size: 30rpx;
|
||||||
|
}
|
||||||
|
.logout-btn::after { border: none; }
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user