物业催缴接口完成(home)

This commit is contained in:
张文涛 2025-05-07 21:42:04 +08:00
parent 9a9c57acb6
commit 32a2258ac8
10 changed files with 640 additions and 725 deletions

4
api/fee.ts Normal file
View File

@ -0,0 +1,4 @@
import { get, post, put, del } from '../utils/request';
export const feeInfo = (data : any = {}) => get('v1/fee/info', data);

View File

@ -22,3 +22,9 @@ export const logout = (data : any) => get('v1/logout', data);
// 获取权限
export const menu = (data : any) => get('v1/menu', data);
// 修改用户信息
export const changeInfo = (data : any) => post('v2/change/info', data)
// 用户协议隐私政策
export const configGet = (data : any) => get('v2/config/get', data);

View File

@ -186,11 +186,11 @@
title: '物业催缴',
type: 'call'
},
{
image: uni.$globalData?.RESOURCE_URL + 'home/grid/tousu.png',
title: '投诉管理',
type: 'complaint'
},
// {
// image: uni.$globalData?.RESOURCE_URL + 'home/grid/tousu.png',
// title: '',
// type: 'complaint'
// },
// {
// image: uni.$globalData?.RESOURCE_URL + 'home/grid/fangke.png',
// title: '访',
@ -216,11 +216,11 @@
title: '商品核销',
type: 'verification'
},
{
image: uni.$globalData?.RESOURCE_URL + 'home/grid/gongdan.png',
title: '员工权限',
type: 'permissions'
}
// {
// image: uni.$globalData?.RESOURCE_URL + 'home/grid/gongdan.png',
// title: '',
// type: 'permissions'
// }
])

View File

@ -4,7 +4,8 @@
<view class="li-flex li-justify-between li-items-center li-w-94% li-mx-auto li-mt-60">
<view @click="toPages({type:'userInfo'})" class="li-flex li-items-center">
<view class="li-flex li-items-end li-mr-20">
<image class="li-w-100 li-h-100 li-rd-50% border-4-white" :src="user_info.avatar" mode="">
<image class="li-w-100 li-h-100 li-rd-50% border-4-white"
:src="user_info?.avatar?user_info?.avatar:'/static/m_avatar.png'" mode="">
</image>
</view>
<view class="li-flex li-flex-col">
@ -84,16 +85,11 @@
import { onShow, onReachBottom, Uni } from "@dcloudio/uni-app"
import { ref } from "vue"
import { useToast } from '@/uni_modules/wot-design-uni'
import { userInfo } from '@/api/login'
const Toast = useToast()
declare const uni : Uni
const user_info = ref({
"realname": "里派",
"avatar": "/static/m_avatar.png",
"owner": {
"name": "里派(杭州)网络科技有限公司"
}
})
const user_info = ref({})
const mine_back = uni.$globalData?.RESOURCE_URL + 'mine/mine-back1.png'
const card_back = uni.$globalData?.RESOURCE_URL + 'mine/card-back.png'
@ -151,12 +147,12 @@
// number: 0,
// icon: uni.$globalData?.RESOURCE_URL + 'mine/icon/menjin.png'
// },
{
title: '用户协议',
number: 0,
icon: uni.$globalData?.RESOURCE_URL + 'mine/icon/pandian.png',
type: 'protocol'
},
// {
// title: '',
// number: 0,
// icon: uni.$globalData?.RESOURCE_URL + 'mine/icon/pandian.png',
// type: 'protocol'
// },
{
title: '隐私政策',
number: 0,
@ -240,12 +236,19 @@
}
}
const getUserInfo = async () => {
const res = await userInfo()
user_info.value = res.data
}
onShow(async () => {
const userInfo = await uni.$store.state.userInfos
userInfo.realname && (user_info.value.realname = userInfo.realname)
userInfo.avatar && (user_info.value.avatar = userInfo.avatar)
userInfo.owner.name && (user_info.value.owner.name = userInfo.owner.name)
// const userInfo = await uni.$store.state.userInfos
// userInfo.realname && (user_info.value.realname = userInfo.realname)
// userInfo.avatar && (user_info.value.avatar = userInfo.avatar)
// userInfo.owner.name && (user_info.value.owner.name = userInfo.owner.name)
getUserInfo()
})
</script>

View File

@ -25,6 +25,7 @@
import { onLoad } from '@dcloudio/uni-app';
import { useNavigation } from '@/hooks/useNavigation';
import { useToast } from '@/uni_modules/wot-design-uni';
import { configGet } from '@/api/login'
const Toast = useToast();
@ -36,7 +37,13 @@
} = useNavigation();
const paramsType = ref('1')
const rawHtml = ref('<div style="text-align:center;background-color: #007AFF;"><div >我是内容</div><img src="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni@2x.png"/></div>')
const rawHtml = ref('')
const getConfigGet = async () => {
const res = await configGet({group_id:29})
rawHtml.value = res.data.emp_privacy_agreement
}
//
@ -62,6 +69,7 @@
//
onLoad((options) => {
checkRouteStack();
getConfigGet()
paramsType.value = options.type
});
</script>

File diff suppressed because it is too large Load Diff

View File

@ -30,8 +30,9 @@
</view>
<view class="section-right">
<view class="user-avatar">
<image v-if="userInfo.avatar" :src="userInfo.avatar" mode="aspectFill"></image>
<view v-else class="default-avatar">{{ userInfo.nickname.substring(0, 1) }}</view>
<image :src="user_info.avatar?user_info.avatar:'/static/m_avatar.png'" mode="aspectFill">
</image>
<!-- <view v-else class="default-avatar">{{ userInfo.realname.substring(0, 1) }}</view> -->
</view>
<text class="ri-arrow-right-s-line arrow-icon"></text>
</view>
@ -44,7 +45,7 @@
</view>
<view class="section-right">
<view class="input-wrapper">
<input class="form-input" type="text" v-model="userInfo.nickname" placeholder="请输入昵称"
<input class="form-input" type="text" v-model="user_info.realname" placeholder="请输入昵称"
@blur="validateNickname" />
</view>
<text class="ri-arrow-right-s-line arrow-icon"></text>
@ -57,7 +58,7 @@
<text class="form-label">手机号</text>
</view>
<view class="section-right">
<text class="phone-text">{{ formatPhone(userInfo.phone) }}</text>
<text class="phone-text">{{ formatPhone(user_info.username) }}</text>
</view>
</view>
</view>
@ -69,22 +70,8 @@
</view>
<!-- 头像选择弹窗 -->
<wd-popup v-model="showAvatarPopup" position="bottom">
<view class="avatar-popup">
<view class="popup-title">修改头像</view>
<view class="avatar-options">
<view class="option-item" @click="handleSelectAlbum">
<text class="ri-image-2-line option-icon"></text>
<text class="option-text">从相册选择</text>
</view>
<view class="option-item" @click="handleTakePhoto">
<text class="ri-camera-line option-icon"></text>
<text class="option-text">拍照</text>
</view>
</view>
<view class="cancel-btn" @click="showAvatarPopup = false">取消</view>
</view>
</wd-popup>
<wd-action-sheet v-model="showAvatarPopup" :actions="avatarActions" @select="handleAvatarSelect" />
<wd-toast />
</view>
</template>
@ -100,6 +87,17 @@
import {
onLoad
} from '@dcloudio/uni-app'
import {
useToast
} from '@/uni_modules/wot-design-uni';
import {
fileUpload
} from '@/utils/common'
import {
changeInfo,
userInfo
} from '@/api/login';
const Toast = useToast();
// 使 composable
const {
@ -110,15 +108,31 @@
//
const userInfo = reactive({
nickname: '里派用户',
phone: '13800138000',
avatar: ''
});
const user_info = ref({})
//
const showAvatarPopup = ref(false);
//
const avatarActions = [{
name: '从相册选择',
},
{
name: '拍照',
}
];
/**
* 处理头像选择
*/
const handleAvatarSelect = (action) => {
if (action.index === 0) {
handleSelectAlbum();
} else if (action.index === 1) {
handleTakePhoto();
}
};
/**
* 格式化手机号码为带星号格式
*/
@ -131,12 +145,8 @@
* 校验昵称
*/
const validateNickname = () => {
if (!userInfo.nickname.trim()) {
uni.showToast({
title: '昵称不能为空',
icon: 'none'
});
userInfo.nickname = '里派用户';
if (!user_info.value.realname.trim()) {
Toast.error('昵称不能为空')
}
};
@ -155,27 +165,17 @@
count: 1,
sizeType: ['compressed'],
sourceType: ['album'],
success: (res) => {
success: async (res) => {
//
showAvatarPopup.value = false;
//
const tempFilePath = res.tempFilePaths[0];
// URL
//
uni.showLoading({
title: '上传中...'
});
setTimeout(() => {
uni.hideLoading();
userInfo.avatar = tempFilePath;
uni.showToast({
title: '头像已更新',
icon: 'success'
});
}, 1000);
//
const fileUrl = await fileUpload(tempFilePath)
Toast.success('上传成功')
user_info.value.avatar = fileUrl
}
});
};
@ -188,27 +188,17 @@
count: 1,
sizeType: ['compressed'],
sourceType: ['camera'],
success: (res) => {
success: async (res) => {
//
showAvatarPopup.value = false;
//
const tempFilePath = res.tempFilePaths[0];
// URL
//
uni.showLoading({
title: '上传中...'
});
setTimeout(() => {
uni.hideLoading();
userInfo.avatar = tempFilePath;
uni.showToast({
title: '头像已更新',
icon: 'success'
});
}, 1000);
//
const fileUrl = await fileUpload(tempFilePath)
Toast.success('上传成功')
user_info.value.avatar = fileUrl
}
});
};
@ -229,13 +219,10 @@
/**
* 保存用户信息
*/
const saveUserInfo = () => {
const saveUserInfo = async () => {
//
if (!userInfo.nickname.trim()) {
uni.showToast({
title: '昵称不能为空',
icon: 'none'
});
if (!user_info.value.realname.trim()) {
Toast.error('昵称不能为空')
return;
}
@ -244,44 +231,29 @@
title: '保存中...'
});
//
setTimeout(() => {
//
uni.hideLoading();
//
uni.setStorageSync('userInfo', JSON.stringify(userInfo));
//
uni.showToast({
title: '保存成功',
icon: 'success'
});
//
const res = await changeInfo({
real_name: user_info.value.realname,
avatar: user_info.value.avatar
})
uni.hideLoading()
if (res.code == 200) {
Toast.success('保存成功')
setTimeout(() => {
goBack();
}, 1500);
}, 1000);
};
/**
* 返回上一页
*/
const goBack = () => {
uni.navigateBack();
uni.navigateBack();
}, 500)
}
};
const getUserInfo = async () => {
const res = await userInfo()
user_info.value = res.data
}
onMounted(() => {
checkRouteStack()
//
const userInfoStorage = uni.getStorageSync('userInfo');
if (userInfoStorage) {
Object.assign(userInfo, JSON.parse(userInfoStorage));
}
getUserInfo()
});
</script>

View File

@ -42,13 +42,13 @@
<text class="ri-arrow-right-s-line arrow"></text>
</view>
<view class="setting-item" @click="handleUserAgreement">
<!-- <view class="setting-item" @click="handleUserAgreement">
<view class="left">
<text class="ri-file-list-3-line icon"></text>
<text class="title">用户协议</text>
</view>
<text class="ri-arrow-right-s-line arrow"></text>
</view>
</view> -->
<view class="setting-item" @click="checkUpdate">
<view class="left">

View File

@ -61,68 +61,10 @@
.li-w-100{width:100rpx}
.li-w-full-80{width:80%}
.bg-0070F0{background-color:rgb(0,112,240)}
.border-4-white{border-style:solid;border-color:rgb(255,255,255);border-width:4rpx}
.bg-FFFFFF{background-color:rgb(255,255,255)}
.bg-f9f9f9{background-color:rgb(249,249,249)}
.border-4-white{border-style:solid;border-color:rgb(255,255,255);border-width:4rpx}
.li-font-bold{font-weight:bold}
.li-mb-8{margin-bottom:8rpx}
.li-ml-15{margin-left:15rpx}
.li-ml-6{margin-left:6rpx}
.li-mr-6{margin-right:6rpx}
.li-p-15{padding:15rpx}
.li-pb-15{padding-bottom:15rpx}
.li-pb-30{padding-bottom:30rpx}
.li-pt-25{padding-top:25rpx}
.li-pt-4{padding-top:4rpx}
.li-text-009aff-color{color:rgb(0,154,255)}
.li-text-24{font-size:24rpx}
.li-text-32{font-size:32rpx}
.li-text-333333-color{color:rgb(51,51,51)}
.li-text-36{font-size:36rpx}
.li-text-55{font-size:55rpx}
.li-text-70{font-size:70rpx}
.li-text-9a9a9a-color{color:rgb(154,154,154)}
.li-text-ff0000-color{color:rgb(255,0,0)}
.li-w-full-100{width:100%}
.li-w-full-92{width:92%}
.li-font-550{font-weight:550}
.li-h-68{height:68rpx}
.li-mt-100{margin-top:100rpx}
.li-mt-28{margin-top:28rpx}
.li-mt-32{margin-top:32rpx}
.li-mt-90{margin-top:90rpx}
.li-mx-10{margin-left:10rpx;margin-right:10rpx}
.li-pt-270{padding-top:270rpx}
.li-rd-40{border-radius:40rpx}
.li-text-000000-color{color:rgb(0,0,0)}
.li-text-2EA1EA-color{color:rgb(46,161,234)}
.li-text-a5a5a5-color{color:rgb(165,165,165)}
.li-w-150{width:150rpx}
.li-w-420{width:420rpx}
.li-w-full-85{width:85%}
.li-w-full-90{width:90%}
.li-h-110{height:110rpx}
.li-items-start{align-items:start}
.li-mb-12{margin-bottom:12rpx}
.li-mb-20{margin-bottom:20rpx}
.li-mr-12{margin-right:12rpx}
.li-mr-3{margin-right:3rpx}
.li-mt-40{margin-top:40rpx}
.li-pb-25{padding-bottom:25rpx}
.li-pl-20{padding-left:20rpx}
.li-pl-30{padding-left:30rpx}
.li-pr-30{padding-right:30rpx}
.li-pt-20{padding-top:20rpx}
.li-pt-30{padding-top:30rpx}
.li-py-6{padding-top:6rpx;padding-bottom:6rpx}
.li-rd-20{border-radius:20rpx}
.li-text-40{font-size:40rpx}
.li-text-5f5f5f-color{color:rgb(95,95,95)}
.li-text-666-color{color:rgb(102,102,102)}
.li-text-right{text-align:right}
.li-w-110{width:110rpx}
.li-w-400{width:400rpx}
.overflow-hidden{overflow:hidden}
.li-h-240{height:240rpx}
.li-h-250{height:250rpx}
.li-h-50{height:50rpx}
@ -141,11 +83,16 @@
.li-pb-10{padding-bottom:10rpx}
.li-pb-14{padding-bottom:14rpx}
.li-pb-20{padding-bottom:20rpx}
.li-pt-20{padding-top:20rpx}
.li-pt-8{padding-top:8rpx}
.li-rd-20{border-radius:20rpx}
.li-rd-tl-30-important{border-top-left-radius:30rpx !important}
.li-rd-tr-30-important{border-top-right-radius:30rpx !important}
.li-text-000000-color{color:rgb(0,0,0)}
.li-text-19171B-color{color:rgb(25,23,27)}
.li-text-20{font-size:20rpx}
.li-text-24{font-size:24rpx}
.li-text-32{font-size:32rpx}
.li-text-706e70-color{color:rgb(112,110,112)}
.li-text-B2B2B2-color{color:rgb(178,178,178)}
.li-text-BBBDDA-color{color:rgb(187,189,218)}
@ -157,10 +104,63 @@
.li-w-50{width:50rpx}
.li-w-60{width:60rpx}
.li-w-full-94{width:94%}
.li-font-550{font-weight:550}
.li-h-68{height:68rpx}
.li-mt-100{margin-top:100rpx}
.li-mt-28{margin-top:28rpx}
.li-mt-32{margin-top:32rpx}
.li-mt-90{margin-top:90rpx}
.li-mx-10{margin-left:10rpx;margin-right:10rpx}
.li-pt-270{padding-top:270rpx}
.li-rd-40{border-radius:40rpx}
.li-text-2EA1EA-color{color:rgb(46,161,234)}
.li-text-a5a5a5-color{color:rgb(165,165,165)}
.li-w-150{width:150rpx}
.li-w-420{width:420rpx}
.li-w-full-85{width:85%}
.li-w-full-90{width:90%}
.li-mb-8{margin-bottom:8rpx}
.li-ml-15{margin-left:15rpx}
.li-ml-6{margin-left:6rpx}
.li-mr-6{margin-right:6rpx}
.li-p-15{padding:15rpx}
.li-pb-15{padding-bottom:15rpx}
.li-pb-30{padding-bottom:30rpx}
.li-pt-25{padding-top:25rpx}
.li-pt-4{padding-top:4rpx}
.li-text-009aff-color{color:rgb(0,154,255)}
.li-text-333333-color{color:rgb(51,51,51)}
.li-text-36{font-size:36rpx}
.li-text-55{font-size:55rpx}
.li-text-70{font-size:70rpx}
.li-text-9a9a9a-color{color:rgb(154,154,154)}
.li-text-ff0000-color{color:rgb(255,0,0)}
.li-w-full-100{width:100%}
.li-w-full-92{width:92%}
.li-h-110{height:110rpx}
.li-items-start{align-items:start}
.li-mb-12{margin-bottom:12rpx}
.li-mb-20{margin-bottom:20rpx}
.li-mr-12{margin-right:12rpx}
.li-mr-3{margin-right:3rpx}
.li-mt-40{margin-top:40rpx}
.li-pb-25{padding-bottom:25rpx}
.li-pl-20{padding-left:20rpx}
.li-pl-30{padding-left:30rpx}
.li-pr-30{padding-right:30rpx}
.li-pt-30{padding-top:30rpx}
.li-py-6{padding-top:6rpx;padding-bottom:6rpx}
.li-text-40{font-size:40rpx}
.li-text-5f5f5f-color{color:rgb(95,95,95)}
.li-text-666-color{color:rgb(102,102,102)}
.li-text-right{text-align:right}
.li-w-110{width:110rpx}
.li-w-400{width:400rpx}
.overflow-hidden{overflow:hidden}
.li-mb-25{margin-bottom:25rpx}
.li-font-400{font-weight:400}
.li-m-30{margin:30rpx}
.li-text-595959-color{color:rgb(89,89,89)}
.li-mb-25{margin-bottom:25rpx}
.li-mb-30{margin-bottom:30rpx}
.li-ml-10{margin-left:10rpx}
.li-mr-200{margin-right:200rpx}
@ -190,46 +190,43 @@
.li-h-90{height:90rpx}
.li-text-47{font-size:47rpx}
.li-w-90{width:90rpx}
.li-flex-1{flex:1}
.li-flex-wrap{flex-wrap:wrap}
.li-mt-25{margin-top:25rpx}
.li-mt-5{margin-top:5rpx}
.li-text-999999-color{color:rgb(153,153,153)}
.li-w-160{width:160rpx}
.li-block{display:block}
.li-items-baseline{align-items:baseline}
.li-mr-15{margin-right:15rpx}
.li-mt-5{margin-top:5rpx}
.li-opacity-100{undefined:1}
.li-rd-12{border-radius:12rpx}
.li-rd-16{border-radius:16rpx}
.li-text-0a4696-color{color:rgb(10,70,150)}
.li-flex-1{flex:1}
.li-flex-wrap{flex-wrap:wrap}
.li-mt-25{margin-top:25rpx}
.li-text-999999-color{color:rgb(153,153,153)}
.li-w-160{width:160rpx}
.li-line-clamp-2{overflow:hidden;display:-webkit-box;line-clamp:2;-webkit-box-orient:vertical;-webkit-line-clamp:2}
.li-w-full-96{width:96%}
.li-mt-200{margin-top:200rpx}
.li-pt-6{padding-top:6rpx}
.li-my-10{margin-top:10rpx;margin-bottom:10rpx}
.li-p-20{padding:20rpx}
.li-px-20{padding-left:20rpx;padding-right:20rpx}
.li-py-10{padding-top:10rpx;padding-bottom:10rpx}
.li-py-60{padding-top:60rpx;padding-bottom:60rpx}
.li-rd-8{border-radius:8rpx}
.li-text-dddddd-color{color:rgb(221,221,221)}
.li-text-ff9900-color{color:rgb(255,153,0)}
.li-mr-180{margin-right:180rpx}
.li-opacity-80{undefined:0.8}
.li-pb-40{padding-bottom:40rpx}
.li-px-20{padding-left:20rpx;padding-right:20rpx}
.li-py-10{padding-top:10rpx;padding-bottom:10rpx}
.li-py-100{padding-top:100rpx;padding-bottom:100rpx}
.li-py-60{padding-top:60rpx;padding-bottom:60rpx}
.li-rd-30{border-radius:30rpx}
.li-text-100{font-size:100rpx}
.li-text-3e9bff-color{color:rgb(62,155,255)}
.li-text-50{font-size:50rpx}
.li-text-52c41a-color{color:rgb(82,196,26)}
.li-text-ccc-color{color:rgb(204,204,204)}
.li-text-ff4d4f-color{color:rgb(255,77,79)}
.li-my-10{margin-top:10rpx;margin-bottom:10rpx}
.li-p-20{padding:20rpx}
.li-rd-8{border-radius:8rpx}
.li-text-dddddd-color{color:rgb(221,221,221)}
.li-text-ff9900-color{color:rgb(255,153,0)}

View File

@ -1,4 +1,6 @@
import CryptoJS from 'crypto-js';
import { Uni } from '@dcloudio/uni-app'
declare const uni : Uni
/**
* 2
@ -147,15 +149,15 @@ export const VersionUpdate = () => {
if (uni.canIUse('getUpdateManager')) {
const updateManager = uni.getUpdateManager()
// 向小程序后台请求完新版本信息
updateManager.onCheckForUpdate(function(res) {
updateManager.onCheckForUpdate(function (res) {
if (res.hasUpdate) {
//小程序有新版本,静默下载新版本,新版本下载完成
updateManager.onUpdateReady(function() {
updateManager.onUpdateReady(function () {
//模态弹窗(确认、取消)
uni.showModal({
title: '更新提示',
content: '小程序已发布新版本,是否重启?',
success: function(res) {
success: function (res) {
//用户点击确定
if (res.confirm) {
//当新版本下载完成,调用该方法会强制当前小程序应用上新版本并重启
@ -168,7 +170,7 @@ export const VersionUpdate = () => {
title: '提示',
content: '小程序已发布新版本,是否重启',
showCancel: false, //隐藏取消按钮
success: function(res) {
success: function (res) {
//第二次提示后,强制更新
if (res.confirm) {
// 当新版本下载完成,调用该方法会强制当前小程序应用上新版本并重启
@ -184,7 +186,7 @@ export const VersionUpdate = () => {
})
})
// 当新版本下载失败
updateManager.onUpdateFailed(function() {
updateManager.onUpdateFailed(function () {
uni.showModal({
title: '提示',
content: '请您删除当前小程序,重新打开小程序',
@ -204,21 +206,21 @@ export const VersionUpdate = () => {
/*
base64编码
*/
export const base64_encrypt = (data: String) => {
export const base64_encrypt = (data : String) => {
return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(data))
}
/*
base64解码
*/
export const base64_decrypt = (cipher: any) => {
export const base64_decrypt = (cipher : any) => {
return CryptoJS.enc.Base64.parse(cipher).toString(CryptoJS.enc.Utf8)
}
/*
md5加密
*/
export const md5 = (data: String) => {
export const md5 = (data : String) => {
return CryptoJS.MD5(data).toString()
}
@ -233,37 +235,37 @@ import { throttle } from '@/utils/common'
// 在setup中使用
const handleClick = throttle(() => {
// 你的业务逻辑
console.log('点击事件被触发')
// 你的业务逻辑
console.log('点击事件被触发')
}, 500)
// 在模板中使用
<button @click="handleClick"></button>
*/
export const throttle = (fn: Function, delay: number = 500): Function => {
let timer: number | null = null;
let lastTime: number = 0;
export const throttle = (fn : Function, delay : number = 500) : Function => {
let timer : number | null = null;
let lastTime : number = 0;
return function (this: any, ...args: any[]) {
const currentTime = Date.now();
return function (this : any, ...args : any[]) {
const currentTime = Date.now();
if (!lastTime) {
lastTime = currentTime;
}
if (!lastTime) {
lastTime = currentTime;
}
if (currentTime - lastTime >= delay) {
fn.apply(this, args);
lastTime = currentTime;
} else {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
fn.apply(this, args);
lastTime = Date.now();
}, delay - (currentTime - lastTime));
}
};
if (currentTime - lastTime >= delay) {
fn.apply(this, args);
lastTime = currentTime;
} else {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
fn.apply(this, args);
lastTime = Date.now();
}, delay - (currentTime - lastTime));
}
};
};
/**
@ -277,22 +279,52 @@ import { debounce } from '@/utils/common'
// 在setup中使用
const handleSearch = debounce((value: string) => {
// 你的搜索逻辑
console.log('搜索:', value)
// 你的搜索逻辑
console.log('搜索:', value)
}, 300)
// 在模板中使用
<input @input="handleSearch" />
*/
export const debounce = (fn: Function, delay: number = 500): Function => {
let timer: number | null = null;
export const debounce = (fn : Function, delay : number = 500) : Function => {
let timer : number | null = null;
return function (this: any, ...args: any[]) {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
fn.apply(this, args);
}, delay);
};
};
return function (this : any, ...args : any[]) {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
fn.apply(this, args);
}, delay);
};
};
function getBaseUrl() {
// @ts-ignore
return uni.$globalData?.BASE_URL + 'v1/upload'
}
export const fileUpload = (data : any) => {
uni.showLoading({
title: '上传中...'
})
return new Promise((resolve, reject) => {
uni.uploadFile({
url: getBaseUrl(),
filePath: data,
name: 'file',
method: 'POST',
header: {
'Authorization': 'Bearer ' + uni.$store.state.token
},
success: (res) => {
resolve(JSON.parse(res.data).data.filePath);
},
complete:() =>{
uni.hideLoading()
}
});
})
}