修复审核不通过的代码
This commit is contained in:
@@ -96,7 +96,7 @@
|
|||||||
"quickapp" : {},
|
"quickapp" : {},
|
||||||
/* 小程序特有相关 */
|
/* 小程序特有相关 */
|
||||||
"mp-weixin" : {
|
"mp-weixin" : {
|
||||||
"appid" : "wxa6184796ceba80ca",
|
"appid" : "wx40625124315d2de1",
|
||||||
"setting" : {
|
"setting" : {
|
||||||
"urlCheck" : false
|
"urlCheck" : false
|
||||||
},
|
},
|
||||||
|
|||||||
85
huakai-app/pageSubPack/api/auth.js
Normal file
85
huakai-app/pageSubPack/api/auth.js
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
/**
|
||||||
|
* 登录状态管理工具
|
||||||
|
* 仅在用户点击需要身份认证的功能时才要求登录
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查用户是否已登录
|
||||||
|
* @returns {boolean} true 已登录,false 未登录
|
||||||
|
*/
|
||||||
|
export function isLoggedIn() {
|
||||||
|
const token = uni.getStorageSync('token');
|
||||||
|
return !!token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 要求登录 — 未登录时跳转登录页,已登录直接执行回调
|
||||||
|
* 登录页提供返回/取消按钮,用户可拒绝登录
|
||||||
|
*
|
||||||
|
* @param {Object} options
|
||||||
|
* @param {Function} [options.onLoggedIn] - 已登录或登录成功后执行的回调
|
||||||
|
* @param {string} [options.title] - 展示给用户的提示标题(为什么需要登录)
|
||||||
|
* @param {Function} [options.onCancel] - 用户取消登录后的回调
|
||||||
|
*/
|
||||||
|
export function requireAuth({ onLoggedIn, title, onCancel } = {}) {
|
||||||
|
if (isLoggedIn()) {
|
||||||
|
if (onLoggedIn) onLoggedIn();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 弹窗询问用户是否去登录,用户可拒绝("暂不")
|
||||||
|
const tipTitle = title ? `"${title}"需要登录` : '该功能需要登录';
|
||||||
|
uni.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: `${tipTitle},是否去登录?`,
|
||||||
|
confirmText: '去登录',
|
||||||
|
cancelText: '暂不',
|
||||||
|
success: (modalRes) => {
|
||||||
|
if (modalRes.confirm) {
|
||||||
|
// 用户点击"去登录"
|
||||||
|
uni.setStorageSync('pendingAuthCallback', {
|
||||||
|
time: Date.now(),
|
||||||
|
title: title || ''
|
||||||
|
});
|
||||||
|
|
||||||
|
uni.navigateTo({
|
||||||
|
url: '/pageSubPack/loginSub/pwd-login',
|
||||||
|
events: {
|
||||||
|
loginSuccess: () => {
|
||||||
|
if (onLoggedIn) onLoggedIn();
|
||||||
|
uni.removeStorageSync('pendingAuthCallback');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 用户点击"暂不",留在当前页
|
||||||
|
if (onCancel) onCancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除登录状态
|
||||||
|
*/
|
||||||
|
export function clearLoginState() {
|
||||||
|
uni.removeStorageSync('token');
|
||||||
|
uni.removeStorageSync('userId');
|
||||||
|
uni.removeStorageSync('currentVillageId');
|
||||||
|
uni.removeStorageSync('pendingAuthCallback');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存登录成功后的 token 和用户信息
|
||||||
|
* @param {Object} data - 登录接口返回的 data
|
||||||
|
*/
|
||||||
|
export function saveLoginData(data) {
|
||||||
|
if (data.token) {
|
||||||
|
uni.setStorageSync('token', data.token);
|
||||||
|
}
|
||||||
|
if (data.userId) {
|
||||||
|
uni.setStorageSync('userId', data.userId);
|
||||||
|
}
|
||||||
|
const currentVillageId = data.currentVillageId || 0;
|
||||||
|
uni.setStorageSync('currentVillageId', currentVillageId);
|
||||||
|
}
|
||||||
@@ -42,12 +42,20 @@ export default function request(url, data = {}, method = "GET") {
|
|||||||
|
|
||||||
const resData = res.data || {};
|
const resData = res.data || {};
|
||||||
|
|
||||||
// token 过期
|
// token 过期 — 清除登录态,提示用户,但不强制跳转(用户可继续浏览非敏感页面)
|
||||||
if (resData.code === 401) {
|
if (resData.code === 401) {
|
||||||
uni.showToast({ title: '登录过期,请重新登录', icon: 'none' });
|
uni.showToast({ title: '登录已过期,请重新登录', icon: 'none', duration: 2000 });
|
||||||
uni.clearStorageSync('token');
|
uni.removeStorageSync('token');
|
||||||
|
uni.removeStorageSync('userId');
|
||||||
|
// 使用 navigateTo 而非 reLaunch,用户可通过返回按钮退出登录页
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
uni.navigateTo({
|
||||||
|
url: '/pageSubPack/loginSub/pwd-login',
|
||||||
|
fail: () => {
|
||||||
|
// 如果 navigateTo 失败(如页面栈满),则用 reLaunch
|
||||||
uni.reLaunch({ url: '/pageSubPack/loginSub/pwd-login' });
|
uni.reLaunch({ url: '/pageSubPack/loginSub/pwd-login' });
|
||||||
|
}
|
||||||
|
});
|
||||||
}, 1500);
|
}, 1500);
|
||||||
reject({ msg: '登录过期', code: 401 });
|
reject({ msg: '登录过期', code: 401 });
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="login-page">
|
<view class="login-page">
|
||||||
<view class="status_bar"></view>
|
<view class="status_bar"></view>
|
||||||
|
<!-- 自定义导航栏:返回按钮 — 用户可拒绝登录 -->
|
||||||
|
<view class="custom-nav">
|
||||||
|
<view class="back-btn" @click="handleCancel">
|
||||||
|
<uni-icons type="arrow-left" size="24" color="#333"></uni-icons>
|
||||||
|
<text class="back-text">返回</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
<!-- 登录标题 -->
|
<!-- 登录标题 -->
|
||||||
<view class="login-title">手机验证码登录</view>
|
<view class="login-title">手机验证码登录</view>
|
||||||
|
|
||||||
@@ -13,14 +20,6 @@
|
|||||||
<uni-easyinput class="input-content" type="number" v-model="phoneNumber"
|
<uni-easyinput class="input-content" type="number" v-model="phoneNumber"
|
||||||
placeholder="请输入手机号" :inputBorder="false" maxlength="11" :placeholderStyle="placeholderStyle">
|
placeholder="请输入手机号" :inputBorder="false" maxlength="11" :placeholderStyle="placeholderStyle">
|
||||||
</uni-easyinput>
|
</uni-easyinput>
|
||||||
<!-- <input
|
|
||||||
class="input-content"
|
|
||||||
type="number"
|
|
||||||
placeholder="请输入手机号"
|
|
||||||
v-model="phoneNumber"
|
|
||||||
maxlength="11"
|
|
||||||
@input="checkForm"
|
|
||||||
/> -->
|
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 验证码输入框 + 获取验证码按钮 -->
|
<!-- 验证码输入框 + 获取验证码按钮 -->
|
||||||
@@ -56,7 +55,7 @@
|
|||||||
v-else
|
v-else
|
||||||
></uni-icons>
|
></uni-icons>
|
||||||
</view>
|
</view>
|
||||||
<text class="agreement-text" @click.stop="goToPrivacy">我已阅读并同意<text class="agreePrivacy">《用户隐私政策》</text></text>
|
<text class="agreement-text" @click.stop="goToPrivacy">我已阅读并同意<text class="agreePrivacy" @click.stop="goToPrivacy">《用户隐私政策》</text></text>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 登录按钮 -->
|
<!-- 登录按钮 -->
|
||||||
@@ -79,6 +78,7 @@
|
|||||||
import { ref, computed, onUnmounted } from 'vue';
|
import { ref, computed, onUnmounted } from 'vue';
|
||||||
import {getLoginBySms,getSendCode} from '../api/api.js'
|
import {getLoginBySms,getSendCode} from '../api/api.js'
|
||||||
import { showApiError } from '../api/request.js'
|
import { showApiError } from '../api/request.js'
|
||||||
|
import { saveLoginData } from '../api/auth.js'
|
||||||
|
|
||||||
// ========== 响应式数据 ==========
|
// ========== 响应式数据 ==========
|
||||||
// 手机号
|
// 手机号
|
||||||
@@ -109,6 +109,16 @@ const canLogin = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ========== 方法 ==========
|
// ========== 方法 ==========
|
||||||
|
// 用户取消登录 — 返回上一页
|
||||||
|
const handleCancel = () => {
|
||||||
|
const pages = getCurrentPages();
|
||||||
|
if (pages.length > 1) {
|
||||||
|
uni.navigateBack();
|
||||||
|
} else {
|
||||||
|
uni.switchTab({ url: '/pages/paymentIndex/paymentIndex' });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// 检查表单状态
|
// 检查表单状态
|
||||||
const checkForm = () => {
|
const checkForm = () => {
|
||||||
// 无需额外逻辑,计算属性已实时监听
|
// 无需额外逻辑,计算属性已实时监听
|
||||||
@@ -187,43 +197,24 @@ const handleLogin = () => {
|
|||||||
getLoginBySms(params).then(res =>{
|
getLoginBySms(params).then(res =>{
|
||||||
if(res.code === 200){
|
if(res.code === 200){
|
||||||
if(res.data){
|
if(res.data){
|
||||||
uni.setStorageSync('token', res.data.token);
|
saveLoginData(res.data);
|
||||||
// 存用户ID
|
|
||||||
if(res.data.userId) {
|
|
||||||
uni.setStorageSync('userId', res.data.userId);
|
|
||||||
}
|
|
||||||
// 存当前绑定的小区ID,0 表示未绑定
|
|
||||||
const currentVillageId = res.data.currentVillageId || 0;
|
|
||||||
uni.setStorageSync('currentVillageId', currentVillageId);
|
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
uni.showToast({ title: '登录成功', icon: 'success' });
|
uni.showToast({ title: '登录成功', icon: 'success' });
|
||||||
setTimeout(() =>{
|
setTimeout(() =>{
|
||||||
|
// 登录成功后返回来源页
|
||||||
|
uni.navigateBack({
|
||||||
|
fail: () => {
|
||||||
uni.switchTab({ url: '/pages/paymentIndex/paymentIndex' });
|
uni.switchTab({ url: '/pages/paymentIndex/paymentIndex' });
|
||||||
},1500)
|
|
||||||
// }else{
|
|
||||||
// uni.showToast({ title: '登录失败', icon: 'error' });
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
// }else{
|
},1500)
|
||||||
// uni.showToast({ title:'登录失败', icon: 'error' });
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
showApiError(err)
|
showApiError(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// 模拟登录请求
|
|
||||||
// uni.showLoading({
|
|
||||||
// title: '登录中...'
|
|
||||||
// });
|
|
||||||
// uni.showToast({
|
|
||||||
// title:"登录成功",
|
|
||||||
// icon:'success'
|
|
||||||
// })
|
|
||||||
// setTimeout(() =>{
|
|
||||||
// uni.switchTab({ url: '/pages/paymentIndex/paymentIndex' });
|
|
||||||
// },1500)
|
|
||||||
uni.hideLoading()
|
uni.hideLoading()
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -245,17 +236,35 @@ onUnmounted(() => {
|
|||||||
background: repeating-linear-gradient(to bottom, #E2F0FF, #F6FAFF );
|
background: repeating-linear-gradient(to bottom, #E2F0FF, #F6FAFF );
|
||||||
}
|
}
|
||||||
.status_bar {
|
.status_bar {
|
||||||
height: 160px;
|
height: var(--status-bar-height, 88rpx);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ===== 自定义导航:返回/取消按钮 ===== */
|
||||||
|
.custom-nav {
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
}
|
||||||
|
.back-btn {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 10rpx 20rpx;
|
||||||
|
background: rgba(255,255,255,0.9);
|
||||||
|
border-radius: 30rpx;
|
||||||
|
box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.08);
|
||||||
|
}
|
||||||
|
.back-text {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #333;
|
||||||
|
margin-left: 6rpx;
|
||||||
|
}
|
||||||
|
|
||||||
/* 登录标题 */
|
/* 登录标题 */
|
||||||
.login-title {
|
.login-title {
|
||||||
font-size: 52rpx;
|
font-size: 52rpx;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: #333;
|
color: #333;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin-bottom: 142rpx;
|
margin-bottom: 80rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 输入框项 */
|
/* 输入框项 */
|
||||||
@@ -356,9 +365,6 @@ onUnmounted(() => {
|
|||||||
.agreePrivacy{
|
.agreePrivacy{
|
||||||
color: #2F77FD;
|
color: #2F77FD;
|
||||||
}
|
}
|
||||||
/* .agreePrivacy.active{
|
|
||||||
color: #2F77FD;
|
|
||||||
} */
|
|
||||||
/* 登录按钮 */
|
/* 登录按钮 */
|
||||||
.login-btn {
|
.login-btn {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -375,7 +381,6 @@ onUnmounted(() => {
|
|||||||
.login-btn:disabled {
|
.login-btn:disabled {
|
||||||
background-color: #99c8ff;
|
background-color: #99c8ff;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
/* border-radius: 50px; */
|
|
||||||
}
|
}
|
||||||
/* 禁用按钮边框 */
|
/* 禁用按钮边框 */
|
||||||
button:after{
|
button:after{
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="login-page">
|
<view class="login-page">
|
||||||
<view class="status_bar"></view>
|
<view class="status_bar"></view>
|
||||||
|
<!-- 自定义导航栏:返回按钮 — 用户可拒绝登录 -->
|
||||||
|
<view class="custom-nav">
|
||||||
|
<view class="back-btn" @click="handleCancel">
|
||||||
|
<uni-icons type="arrow-left" size="24" color="#333"></uni-icons>
|
||||||
|
<text class="back-text">返回</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
<!-- 标题 -->
|
<!-- 标题 -->
|
||||||
<view class="login-title">账号密码登录</view>
|
<view class="login-title">账号密码登录</view>
|
||||||
|
|
||||||
@@ -46,7 +53,7 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
<text class="agreement-text" @click.stop="goToPrivacy">我已阅读并同意
|
<text class="agreement-text" @click.stop="goToPrivacy">我已阅读并同意
|
||||||
<text class="agreePrivacy" >《用户隐私政策》</text>
|
<text class="agreePrivacy" @click.stop="goToPrivacy">《用户隐私政策》</text>
|
||||||
</text>
|
</text>
|
||||||
</view>
|
</view>
|
||||||
<navigator class="forget-pwd" url="/pageSubPack/loginSub/forget-pwd">忘记密码?</navigator>
|
<navigator class="forget-pwd" url="/pageSubPack/loginSub/forget-pwd">忘记密码?</navigator>
|
||||||
@@ -73,6 +80,7 @@ import { ref, computed } from 'vue';
|
|||||||
import {onLoad} from "@dcloudio/uni-app"
|
import {onLoad} from "@dcloudio/uni-app"
|
||||||
import {getLoginPassword} from '../api/api.js'
|
import {getLoginPassword} from '../api/api.js'
|
||||||
import { showApiError } from '../api/request.js'
|
import { showApiError } from '../api/request.js'
|
||||||
|
import { saveLoginData } from '../api/auth.js'
|
||||||
|
|
||||||
// 响应式数据
|
// 响应式数据
|
||||||
const phoneNumber = ref('');
|
const phoneNumber = ref('');
|
||||||
@@ -103,6 +111,16 @@ const goToPrivacy = () => {
|
|||||||
// 检查表单
|
// 检查表单
|
||||||
const checkForm = () => {};
|
const checkForm = () => {};
|
||||||
|
|
||||||
|
// 用户取消登录 — 返回上一页
|
||||||
|
const handleCancel = () => {
|
||||||
|
const pages = getCurrentPages();
|
||||||
|
if (pages.length > 1) {
|
||||||
|
uni.navigateBack();
|
||||||
|
} else {
|
||||||
|
uni.switchTab({ url: '/pages/paymentIndex/paymentIndex' });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
onLoad(() =>{
|
onLoad(() =>{
|
||||||
});
|
});
|
||||||
@@ -141,25 +159,18 @@ const handleLogin = () => {
|
|||||||
}
|
}
|
||||||
getLoginPassword(params).then(res =>{
|
getLoginPassword(params).then(res =>{
|
||||||
if(res.code === 200){
|
if(res.code === 200){
|
||||||
uni.setStorageSync('token', res.data.token);
|
saveLoginData(res.data);
|
||||||
// 存用户ID
|
|
||||||
if(res.data) {
|
|
||||||
// 存当前绑定的小区ID,0 表示未绑定
|
|
||||||
const currentVillageId = res.data.currentVillageId || 0;
|
|
||||||
uni.setStorageSync('currentVillageId', currentVillageId);
|
|
||||||
uni.setStorageSync('userId',res.data.userId)
|
|
||||||
}
|
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
uni.showToast({ title: '登录成功', icon: 'success' });
|
uni.showToast({ title: '登录成功', icon: 'success' });
|
||||||
setTimeout(() =>{
|
setTimeout(() =>{
|
||||||
uni.switchTab({
|
// 登录成功后返回来源页
|
||||||
url: '/pages/paymentIndex/paymentIndex'
|
uni.navigateBack({
|
||||||
},1000);
|
fail: () => {
|
||||||
})
|
uni.switchTab({ url: '/pages/paymentIndex/paymentIndex' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},1000)
|
||||||
}
|
}
|
||||||
// else {
|
|
||||||
// uni.showToast({ title: res.msg, icon: 'error' });
|
|
||||||
// }
|
|
||||||
|
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
// console.log(err)
|
// console.log(err)
|
||||||
@@ -177,15 +188,34 @@ const handleLogin = () => {
|
|||||||
background: repeating-linear-gradient(180deg, #E2F0FF, #F6FAFF );
|
background: repeating-linear-gradient(180deg, #E2F0FF, #F6FAFF );
|
||||||
}
|
}
|
||||||
.status_bar {
|
.status_bar {
|
||||||
height: 160px;
|
height: var(--status-bar-height, 88rpx);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ===== 自定义导航:返回/取消按钮 ===== */
|
||||||
|
.custom-nav {
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
}
|
||||||
|
.back-btn {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 10rpx 20rpx;
|
||||||
|
background: rgba(255,255,255,0.9);
|
||||||
|
border-radius: 30rpx;
|
||||||
|
box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.08);
|
||||||
|
}
|
||||||
|
.back-text {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #333;
|
||||||
|
margin-left: 6rpx;
|
||||||
|
}
|
||||||
|
|
||||||
.login-title {
|
.login-title {
|
||||||
font-size: 52rpx;
|
font-size: 52rpx;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: #333;
|
color: #333;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin-bottom: 142rpx;
|
margin-bottom: 80rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input-item {
|
.input-item {
|
||||||
@@ -248,9 +278,6 @@ const handleLogin = () => {
|
|||||||
.agreePrivacy{
|
.agreePrivacy{
|
||||||
color: #2F77FD;
|
color: #2F77FD;
|
||||||
}
|
}
|
||||||
/* .agreePrivacy.active{
|
|
||||||
color: #2F77FD;
|
|
||||||
} */
|
|
||||||
|
|
||||||
.forget-pwd {
|
.forget-pwd {
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
@@ -272,7 +299,6 @@ const handleLogin = () => {
|
|||||||
.login-btn:disabled {
|
.login-btn:disabled {
|
||||||
background-color: #99c8ff;
|
background-color: #99c8ff;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
/* border-radius: 50px; */
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/* 禁用按钮边框 */
|
/* 禁用按钮边框 */
|
||||||
|
|||||||
@@ -90,16 +90,11 @@ const handleBtnClick = () => {
|
|||||||
if (currentStep.value < 2) {
|
if (currentStep.value < 2) {
|
||||||
currentStep.value++;
|
currentStep.value++;
|
||||||
} else {
|
} else {
|
||||||
// 立即体验,跳转首页
|
// 立即体验,直接进入首页(不强制登录 — 仅在需要身份的功能上才要求登录)
|
||||||
// 1. 记录引导已完成
|
|
||||||
uni.setStorageSync('hasShowGuide', true);
|
uni.setStorageSync('hasShowGuide', true);
|
||||||
// 2. 跳转首页
|
uni.switchTab({
|
||||||
uni.navigateTo({
|
url: '/pages/paymentIndex/paymentIndex'
|
||||||
url: "/pageSubPack/loginSub/pwd-login"
|
});
|
||||||
})
|
|
||||||
// uni.switchTab({
|
|
||||||
// url: '/pages/index/index'
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="contentStyle" style="">
|
<view class="contentStyle" style="">
|
||||||
<view class="status-bar"></view>
|
<view class="status-bar"></view>
|
||||||
<!-- left-icon="left" @clickLeft="goBack" -->
|
|
||||||
<uni-nav-bar title="生活缴费" backgroundColor="transparent" :border="false">
|
<uni-nav-bar title="生活缴费" backgroundColor="transparent" :border="false">
|
||||||
</uni-nav-bar>
|
</uni-nav-bar>
|
||||||
<view class="topbox">
|
<view class="topbox">
|
||||||
@@ -10,8 +9,15 @@
|
|||||||
</view>
|
</view>
|
||||||
<scroll-view class="page" scroll-y="true">
|
<scroll-view class="page" scroll-y="true">
|
||||||
<view class="container">
|
<view class="container">
|
||||||
<!-- 已缴费/欠费列表 -->
|
<!-- 未登录提示条 -->
|
||||||
<view class="bill-list" v-if="paymentList.length != 0">
|
<view class="login-tip" v-if="!isLogin" @click="handleLoginPrompt">
|
||||||
|
<image class="login-tip-icon" src="https://wuyeadmin.bugtc.com/images/login/phone.png"></image>
|
||||||
|
<text class="login-tip-text">登录后可查看缴费账单</text>
|
||||||
|
<text class="login-tip-link">去登录</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 账单列表(仅登录后显示) -->
|
||||||
|
<view class="bill-list" v-if="isLogin && paymentList.length > 0">
|
||||||
|
|
||||||
<view class="bill-item" @click="goToBill(item)" v-for="item,index in paymentList" :key="index">
|
<view class="bill-item" @click="goToBill(item)" v-for="item,index in paymentList" :key="index">
|
||||||
<image class="billIcon" src="https://wuyeadmin.bugtc.com/images/propertyImgs/water.png"
|
<image class="billIcon" src="https://wuyeadmin.bugtc.com/images/propertyImgs/water.png"
|
||||||
@@ -25,7 +31,6 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="bill-desc">{{item.villageName+"-"+item.buildingName+'-'+formatAddress(item.fullAddress)}}</view>
|
<view class="bill-desc">{{item.villageName+"-"+item.buildingName+'-'+formatAddress(item.fullAddress)}}</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="arrow"></view>
|
<view class="arrow"></view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -38,26 +43,15 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="grid-list">
|
<view class="grid-list">
|
||||||
|
|
||||||
<view class="grid-item" v-for="(item, index) in addList" :key="index" @click="goToAdd(item)">
|
<view class="grid-item" v-for="(item, index) in addList" :key="index" @click="goToAdd(item)">
|
||||||
<view class="icon-box" :class="item.iconClass">
|
<view class="icon-box" :class="item.iconClass">
|
||||||
<image class="iconStyle" :src="item.icon"></image>
|
<image class="iconStyle" :src="item.icon"></image>
|
||||||
</view>
|
</view>
|
||||||
<!-- <text class="item-name">{{ item.name +'费'}}</text> -->
|
|
||||||
<text class="item-name">{{ item.name}}</text>
|
<text class="item-name">{{ item.name}}</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 开启通知按钮 -->
|
|
||||||
<!-- v-if="subscribeAuth !== 'accepted'" -->
|
|
||||||
<!-- <view class="subscribe-btn" @click="requestSubscribeMessageClick">
|
|
||||||
<text class="subscribe-btn-text">开启缴费通知</text>
|
|
||||||
|
|
||||||
</view> -->
|
|
||||||
<!-- <button class="subscribe-btn" @tap="handleWaterElecSubscribe" open-type="subscribeMessage">
|
|
||||||
开启订单状态通知
|
|
||||||
</button> -->
|
|
||||||
<view style="width: 100%;height: 30rpx;"></view>
|
<view style="width: 100%;height: 30rpx;"></view>
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</scroll-view>
|
||||||
@@ -65,216 +59,155 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import {
|
import { ref } from 'vue'
|
||||||
ref,
|
import { onShow, onLoad } from '@dcloudio/uni-app'
|
||||||
onMounted,
|
import { getTopUpSelectByResident, getopenIdByCode, postInsertOpenId } from '/pageSubPack/api/apiSub.js'
|
||||||
computed
|
import { isLoggedIn, requireAuth } from '/pageSubPack/api/auth.js'
|
||||||
|
|
||||||
} from 'vue'
|
const isLogin = ref(false)
|
||||||
import {
|
const paymentList = ref([])
|
||||||
onShow,
|
|
||||||
onReady,
|
|
||||||
onReachBottom,
|
|
||||||
onLoad,
|
|
||||||
onUnload,
|
|
||||||
onPullDownRefresh
|
|
||||||
} from '@dcloudio/uni-app'
|
|
||||||
|
|
||||||
import {
|
|
||||||
getTopUpSelectByResident,
|
|
||||||
getopenIdByCode,
|
|
||||||
postInsertOpenId,
|
|
||||||
postSubscribeAuth
|
|
||||||
} from '/pageSubPack/api/apiSub.js'
|
|
||||||
// 响应式数据
|
|
||||||
const statusBarHeight = ref(20)
|
|
||||||
// const subscribeAuth = ref(uni.getStorageSync('subscribeAuth') || '')
|
|
||||||
|
|
||||||
const paymentList = ref([
|
|
||||||
// {
|
|
||||||
// id: 1,
|
|
||||||
// name: '物业费',
|
|
||||||
// status: '已欠费',
|
|
||||||
// address: '桂花园(别墅)2号楼2层',
|
|
||||||
// icon: "https://wuyeadmin.bugtc.com/images/propertyImgs/property.png",
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// id: 2,
|
|
||||||
// name: '暖气费',
|
|
||||||
// status: '',
|
|
||||||
// address: '山东省日照市东港区桂花园(别墅)2号楼2层',
|
|
||||||
// icon: "https://wuyeadmin.bugtc.com/images/propertyImgs/heating.png",
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// id: 3,
|
|
||||||
// name: '电表',
|
|
||||||
// status: '已欠费',
|
|
||||||
// address: '山东省日照市东港区桂花园(别墅)2号楼2层',
|
|
||||||
// icon: "https://wuyeadmin.bugtc.com/images/propertyImgs/electric.png",
|
|
||||||
// }
|
|
||||||
])
|
|
||||||
|
|
||||||
const addList = ref([
|
const addList = ref([
|
||||||
// {
|
|
||||||
// name: "燃气",
|
|
||||||
// type: "gas",
|
|
||||||
// icon: "https://wuyeadmin.bugtc.com/images/propertyImgs/gas.png",
|
|
||||||
// iconClass: "gas"
|
|
||||||
// },
|
|
||||||
{
|
{
|
||||||
name: "水表",
|
name: "水表",
|
||||||
type: "water",
|
type: "water",
|
||||||
icon: "https://wuyeadmin.bugtc.com/images/propertyImgs/water.png",
|
icon: "https://wuyeadmin.bugtc.com/images/propertyImgs/water.png",
|
||||||
iconClass: "water"
|
iconClass: "water"
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// name: "物业",
|
|
||||||
// type: "property",
|
|
||||||
// icon: "https://wuyeadmin.bugtc.com/images/propertyImgs/property.png",
|
|
||||||
// iconClass: "property"
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// name: "电表",
|
|
||||||
// type: "electric",
|
|
||||||
// icon: "https://wuyeadmin.bugtc.com/images/propertyImgs/electric.png",
|
|
||||||
// iconClass: "electric"
|
|
||||||
// },
|
|
||||||
|
|
||||||
// {
|
|
||||||
// name: "车位",
|
|
||||||
// type: "parking",
|
|
||||||
// icon: "https://wuyeadmin.bugtc.com/images/propertyImgs/parkingIcon.png",
|
|
||||||
// iconClass: "parking"
|
|
||||||
// }
|
|
||||||
])
|
])
|
||||||
|
|
||||||
|
// ===== 刷新登录状态 =====
|
||||||
|
const refreshLoginState = () => {
|
||||||
|
isLogin.value = isLoggedIn();
|
||||||
|
if (!isLogin.value) {
|
||||||
|
// 未登录时清空账单数据
|
||||||
|
paymentList.value = [];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// ===== openid 相关(仅登录后) =====
|
||||||
const postOpenId = async () => {
|
const postOpenId = async () => {
|
||||||
// 获取 openid
|
if (!isLogin.value) return;
|
||||||
try {
|
try {
|
||||||
const loginRes = await wx.login()
|
const loginRes = await wx.login()
|
||||||
if (!loginRes.code) {
|
if (!loginRes.code) {
|
||||||
uni.hideLoading()
|
console.error('wx.login 失败')
|
||||||
uni.showToast({
|
|
||||||
title: '登录失败',
|
|
||||||
icon: 'none'
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 用 code 换 openid
|
const openIdRes = await getopenIdByCode({ code: loginRes.code })
|
||||||
const openIdRes = await getopenIdByCode({
|
|
||||||
code: loginRes.code
|
|
||||||
})
|
|
||||||
if (openIdRes.code !== 200 || !openIdRes.data) {
|
if (openIdRes.code !== 200 || !openIdRes.data) {
|
||||||
uni.hideLoading()
|
console.error('获取openid失败')
|
||||||
uni.showToast({
|
|
||||||
title: '获取openid失败',
|
|
||||||
icon: 'none'
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const openid = openIdRes.data
|
uni.setStorageSync('openid', openIdRes.data)
|
||||||
uni.setStorageSync('openid', openid)
|
|
||||||
|
|
||||||
await postInsertOpenId({
|
await postInsertOpenId({
|
||||||
openid: uni.getStorageSync('openid'),
|
openid: openIdRes.data,
|
||||||
residentUserId: uni.getStorageSync('userId')
|
residentUserId: uni.getStorageSync('userId')
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
uni.showToast({
|
console.error('postOpenId 报错:', err)
|
||||||
title: err.msg,
|
|
||||||
icon: 'none'
|
|
||||||
})
|
|
||||||
console.error('列表接口报错:', err)
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
onShow(() => {
|
|
||||||
// 不再自动请求订阅消息,改为用户点击触发
|
|
||||||
})
|
|
||||||
// 生命周期
|
|
||||||
onReady(() => {})
|
|
||||||
|
|
||||||
onLoad(() => {
|
|
||||||
postOpenId()
|
|
||||||
uni.hideTabBar({
|
|
||||||
animation: false // 关闭动画,更稳定
|
|
||||||
});
|
|
||||||
getPayList()
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
// ===== 获取缴费列表 =====
|
||||||
const getPayList = async () => {
|
const getPayList = async () => {
|
||||||
// 防重复请求
|
if (!isLogin.value) return;
|
||||||
try {
|
try {
|
||||||
const res = await getTopUpSelectByResident({
|
const res = await getTopUpSelectByResident({
|
||||||
residentUserId: uni.getStorageSync('userId')
|
residentUserId: uni.getStorageSync('userId')
|
||||||
})
|
})
|
||||||
const data = res.data
|
paymentList.value = res.data || []
|
||||||
paymentList.value = data
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
uni.showToast({
|
|
||||||
title: err.msg,
|
|
||||||
icon: 'none'
|
|
||||||
})
|
|
||||||
console.error('列表接口报错:', err)
|
console.error('列表接口报错:', err)
|
||||||
} finally {
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// ===== 生命周期 =====
|
||||||
|
onLoad(() => {
|
||||||
|
refreshLoginState();
|
||||||
|
uni.hideTabBar({ animation: false });
|
||||||
|
if (isLogin.value) {
|
||||||
|
postOpenId();
|
||||||
|
getPayList();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
onShow(() => {
|
||||||
|
refreshLoginState();
|
||||||
|
if (isLogin.value) {
|
||||||
|
getPayList();
|
||||||
}
|
}
|
||||||
// 方法
|
});
|
||||||
|
|
||||||
|
// ===== 点击事件(统一用 isLogin 判断) =====
|
||||||
|
|
||||||
|
// 点击"去登录"提示条
|
||||||
|
const handleLoginPrompt = () => {
|
||||||
|
if (isLogin.value) return;
|
||||||
|
requireAuth({
|
||||||
|
title: '查看缴费账单',
|
||||||
|
onLoggedIn: () => {
|
||||||
|
refreshLoginState();
|
||||||
|
getPayList();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 点击账单明细
|
||||||
const goToBill = (item) => {
|
const goToBill = (item) => {
|
||||||
|
if (!isLogin.value) {
|
||||||
|
requireAuth({
|
||||||
|
title: '查看缴费详情',
|
||||||
|
onLoggedIn: () => {
|
||||||
|
refreshLoginState();
|
||||||
|
goToBill(item);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
uni.setStorageSync('arrearsPayment', item)
|
uni.setStorageSync('arrearsPayment', item)
|
||||||
// if (item.balance < 0) {
|
uni.redirectTo({ url: '/pageSubPack/payment-list/arrearsPayment' })
|
||||||
// uni.redirectTo({
|
};
|
||||||
// url: '/pageSubPack/payment-list/arrearsPayment'
|
|
||||||
// })
|
|
||||||
// } else {
|
|
||||||
// uni.redirectTo({
|
|
||||||
// url: '/pageSubPack/payment-list/noArrearsPayment'
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
uni.redirectTo({
|
|
||||||
url: '/pageSubPack/payment-list/arrearsPayment'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
// 点击缴费记录
|
||||||
const goToRecord = () => {
|
const goToRecord = () => {
|
||||||
uni.redirectTo({
|
if (!isLogin.value) {
|
||||||
url: '/pageSubPack/payment-list/paymentRecord'
|
requireAuth({
|
||||||
})
|
title: '查看缴费记录',
|
||||||
|
onLoggedIn: () => {
|
||||||
|
refreshLoginState();
|
||||||
|
goToRecord();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uni.redirectTo({ url: '/pageSubPack/payment-list/paymentRecord' })
|
||||||
|
};
|
||||||
|
|
||||||
|
// 点击新增缴费(水表/电表等)
|
||||||
const goToAdd = (type) => {
|
const goToAdd = (type) => {
|
||||||
|
if (!isLogin.value) {
|
||||||
|
requireAuth({
|
||||||
|
title: '新增缴费',
|
||||||
|
onLoggedIn: () => {
|
||||||
|
refreshLoginState();
|
||||||
|
goToAdd(type);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (type.name == '燃气' || type.name == '暖气') {
|
if (type.name == '燃气' || type.name == '暖气') {
|
||||||
uni.redirectTo({
|
uni.redirectTo({ url: '/pageSubPack/payment-list/selectPaymentEntity' })
|
||||||
url: '/pageSubPack/payment-list/selectPaymentEntity'
|
|
||||||
})
|
|
||||||
} else if (type.name == '水表' || type.name == '电表') {
|
} else if (type.name == '水表' || type.name == '电表') {
|
||||||
uni.redirectTo({
|
uni.redirectTo({ url: '/pageSubPack/payment-list/addHydropower' })
|
||||||
url: '/pageSubPack/payment-list/addHydropower'
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
uni.setStorageSync('addPaymentType', type.name)
|
uni.setStorageSync('addPaymentType', type.name)
|
||||||
}
|
};
|
||||||
|
|
||||||
const formatAddress = (addr) => {
|
const formatAddress = (addr) => {
|
||||||
if (!addr) return ''
|
if (!addr) return ''
|
||||||
return addr.replace(/\d+[层楼]\s*/g, '').replace(/单元\s*/g, '-').replace(/\s+/g, '')
|
return addr.replace(/\d+[层楼]\s*/g, '').replace(/单元\s*/g, '-').replace(/\s+/g, '')
|
||||||
}
|
};
|
||||||
|
|
||||||
const goBack = () => {
|
|
||||||
console.log(uni.getStorageSync('sourcePage'))
|
|
||||||
if (uni.getStorageSync('sourcePage') == 'serviceIndex') {
|
|
||||||
uni.switchTab({
|
|
||||||
url: '/pages/serviceIndex/serviceIndex'
|
|
||||||
})
|
|
||||||
} else if (uni.getStorageSync('sourcePage') == 'index') {
|
|
||||||
uni.switchTab({
|
|
||||||
url: '/pages/index/index'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
uni.removeStorageSync('sourcePage')
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@@ -320,7 +253,31 @@
|
|||||||
bottom: -140rpx;
|
bottom: -140rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {}
|
/* ===== 未登录提示条 ===== */
|
||||||
|
.login-tip {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
background-color: #fff;
|
||||||
|
padding: 24rpx 30rpx;
|
||||||
|
border-radius: 10rpx;
|
||||||
|
margin-bottom: 30rpx;
|
||||||
|
box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.05);
|
||||||
|
}
|
||||||
|
.login-tip-icon {
|
||||||
|
width: 40rpx;
|
||||||
|
height: 40rpx;
|
||||||
|
margin-right: 16rpx;
|
||||||
|
}
|
||||||
|
.login-tip-text {
|
||||||
|
flex: 1;
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
.login-tip-link {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #1677ff;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
.bill-list {
|
.bill-list {
|
||||||
margin-bottom: 40rpx;
|
margin-bottom: 40rpx;
|
||||||
@@ -329,22 +286,6 @@
|
|||||||
border-radius: 10rpx;
|
border-radius: 10rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.empty-state {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
padding: 100rpx 0;
|
|
||||||
color: #ccc;
|
|
||||||
}
|
|
||||||
|
|
||||||
.empty-text {
|
|
||||||
font-size: 32rpx;
|
|
||||||
color: #999;
|
|
||||||
margin-top: 20rpx;
|
|
||||||
margin-bottom: 10rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.bill-item {
|
.bill-item {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -478,20 +419,6 @@
|
|||||||
color: #333;
|
color: #333;
|
||||||
}
|
}
|
||||||
|
|
||||||
.subscribe-btn {
|
|
||||||
margin-top: 20rpx;
|
|
||||||
background-color: #1677ff;
|
|
||||||
padding: 24rpx;
|
|
||||||
border-radius: 10rpx;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.subscribe-btn-text {
|
|
||||||
color: #fff;
|
|
||||||
font-size: 32rpx;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-bar {
|
.status-bar {
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
height: 46px;
|
height: 46px;
|
||||||
|
|||||||
Reference in New Issue
Block a user