修改上传图片接口,登录页加记住密码

This commit is contained in:
zhouyanli
2026-05-28 10:31:38 +08:00
parent 53c4a37854
commit c8c6b7f922
5 changed files with 74 additions and 24 deletions

View File

@@ -1,4 +1,4 @@
import request,{get,post} from "./request.js" import request,{get,post,upload} from "./request.js"
// =======账号密码登录======== // =======账号密码登录========
@@ -65,8 +65,8 @@ export const addRepairList = (data) =>{
return post('/manage/repair/order',data) return post('/manage/repair/order',data)
} }
// 上传图片 // 上传图片
export const uploadFile = (filePath) => { export const uploadFile = (filePath, fileName) => {
return upload(filePath,'/resource/oss/upload'); return upload(filePath, '/api/butler/file/uploadImage', fileName);
} }
// 查询一键开门 // 查询一键开门

View File

@@ -81,20 +81,21 @@ export const put = (url, data) => request(url, data, 'PUT')
// export const putMethod = (url, data) => request(url, data, 'PUT'); // export const putMethod = (url, data) => request(url, data, 'PUT');
// 上传 // 上传
export const upload = (filePath, url) => { export const upload = (filePath, url, fileName) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
uni.uploadFile({ const uploadTask = uni.uploadFile({
url: baseUrl + url, url: baseUrl + url,
filePath: filePath, filePath: filePath,
name: 'file', name: 'file',
fileName: fileName,
header: { header: {
Authorization: 'Bearer ' + (uni.getStorageSync('token') || ''), Authorization: 'Bearer ' + (uni.getStorageSync('token') || ''),
clientid: 'resident' clientid: 'butler'
}, },
success: res => { success: res => {
try { try {
const data = JSON.parse(res.data) const data = JSON.parse(res.data)
resolve(data.data || '') // 直接返回图片地址 resolve(data.data || '')
} catch (e) { } catch (e) {
resolve('') resolve('')
} }

View File

@@ -150,14 +150,15 @@ const uploadImages = async () => {
continue continue
} }
try { try {
const res = await uploadFile(path) // 从路径中提取文件名
// 根据后端实际返回结构调整字段名 const fileName = path.substring(path.lastIndexOf('/') + 1)
uploadedUrls.push(res.url || '') const res = await uploadFile(path, fileName)
uploadedUrls.push(res?.url || '')
} catch (err) { } catch (err) {
uni.showToast({ uni.showToast({
title:err.msg || '图片上传失败', title: err.msg || '图片上传失败',
icon:'error' icon: 'error'
}) })
} }
} }
return uploadedUrls return uploadedUrls

View File

@@ -29,6 +29,15 @@
</view> </view>
<!-- 记住密码 -->
<view class="remember-wrap">
<view class="remember-item" @click="toggleRemember">
<uni-icons type="checkbox-filled" size="18" color="#4D5DFA" v-if="rememberPwd"></uni-icons>
<uni-icons type="checkbox" size="18" color="#999" v-else></uni-icons>
<text class="remember-text">记住密码</text>
</view>
</view>
<!-- 协议勾选 + 忘记密码 --> <!-- 协议勾选 + 忘记密码 -->
<view class="agreement-wrap"> <view class="agreement-wrap">
<view class="agreement-item"> <view class="agreement-item">
@@ -72,6 +81,7 @@
const phoneNumber = ref(''); const phoneNumber = ref('');
const password = ref(''); const password = ref('');
const agreeAgreement = ref(false); // 默认勾选 const agreeAgreement = ref(false); // 默认勾选
const rememberPwd = ref(false);
const placeholderStyle = ref('font-size:24rpx') const placeholderStyle = ref('font-size:24rpx')
// 控制点击变色 // 控制点击变色
// const isClicked = ref(false) // const isClicked = ref(false)
@@ -87,6 +97,10 @@
const toggleAgreement = () => { const toggleAgreement = () => {
agreeAgreement.value = !agreeAgreement.value; agreeAgreement.value = !agreeAgreement.value;
}; };
// 切换记住密码
const toggleRemember = () => {
rememberPwd.value = !rememberPwd.value;
};
// 跳转隐私协议 // 跳转隐私协议
const goToPrivacy = () => { const goToPrivacy = () => {
@@ -100,7 +114,14 @@
const checkForm = () => {}; const checkForm = () => {};
onLoad(() => {}); onLoad(() => {
const savedPhone = uni.getStorageSync('rememberPhone');
const savedPwd = uni.getStorageSync('rememberPassword');
const savedRemember = uni.getStorageSync('rememberPwd');
if (savedPhone) phoneNumber.value = savedPhone;
if (savedPwd) password.value = savedPwd;
if (savedRemember) rememberPwd.value = savedRemember;
});
// 登录逻辑 // 登录逻辑
const handleLogin = () => { const handleLogin = () => {
@@ -138,12 +159,21 @@
if(res.code === 200){ if(res.code === 200){
uni.setStorageSync('token', res.data.token); uni.setStorageSync('token', res.data.token);
// 存用户ID // 存用户ID
if(res.data) { // if(res.data) {
// 存当前绑定的小区ID,0 表示未绑定 // // 存当前绑定的小区ID,0 表示未绑定
// const currentVillageId = res.data.currentVillageId || 0; // // const currentVillageId = res.data.currentVillageId || 0;
// uni.setStorageSync('currentVillageId', currentVillageId); // // uni.setStorageSync('currentVillageId', currentVillageId);
} // }
uni.hideLoading(); uni.hideLoading();
if (rememberPwd.value) {
uni.setStorageSync('rememberPhone', phoneNumber.value);
uni.setStorageSync('rememberPassword', password.value);
uni.setStorageSync('rememberPwd', true);
} else {
uni.removeStorageSync('rememberPhone');
uni.removeStorageSync('rememberPassword');
uni.removeStorageSync('rememberPwd');
}
uni.showToast({ title: '登录成功', icon: 'success' }); uni.showToast({ title: '登录成功', icon: 'success' });
setTimeout(() =>{ setTimeout(() =>{
uni.switchTab({ uni.switchTab({
@@ -228,11 +258,29 @@
font-size: 28rpx; font-size: 28rpx;
} }
.remember-wrap {
display: flex;
align-items: center;
margin: 20rpx 0 0 0;
padding: 0 10rpx;
}
.remember-item {
display: flex;
align-items: center;
}
.remember-text {
font-size: 24rpx;
color: #666;
margin-left: 10rpx;
}
.agreement-wrap { .agreement-wrap {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
margin: 70rpx 0 28rpx 0; margin: 40rpx 0 28rpx 0;
padding: 0 10rpx; padding: 0 10rpx;
} }

View File

@@ -301,11 +301,10 @@ onReady(() => {
.type-tabs { .type-tabs {
display: flex; display: flex;
/* background-color: #fff; */ /* background-color: #fff; */
padding: 20rpx 0rpx; padding: 20rpx 40rpx;
margin-top: 10rpx; margin-top: 10rpx;
justify-content: flex-start; justify-content: flex-start;
gap: 30rpx; /* gap: 20rpx; */
margin: 0rpx 40rpx;
} }
.type-tab-item { .type-tab-item {
@@ -314,6 +313,7 @@ onReady(() => {
color: #999; color: #999;
border: 2rpx solid #999; border: 2rpx solid #999;
border-radius: 198rpx; border-radius: 198rpx;
margin: 0 16rpx 0 0
} }
.type-tab-item.active { .type-tab-item.active {