refactor: 重构多个组件以支持 Vue 3 语法和功能

- 将多个组件转换为 `<script setup>` 语法,提升可读性和性能
- 优化状态管理和事件处理逻辑,简化代码结构
- 更新样式和布局以适应新组件结构
- 添加新功能和修复已知问题,提升用户体验
This commit is contained in:
Yer11214
2026-07-08 18:37:11 +08:00
parent 4d0b0fb5e4
commit 349ffa4f34
189 changed files with 18278 additions and 20758 deletions

View File

@@ -72,83 +72,83 @@
</view>
</template>
<script>
import tool from "@/pages/tabbar/user/utils/tool.vue";
import { getCouponsNum, getFootprintNum } from "@/api/members.js";
import { getUserWallet } from "@/api/members";
<script setup lang="ts">
import { ref, computed } from 'vue'
import {
onLoad,
onShow,
onPullDownRefresh,
onNavigationBarButtonTap,
} from '@dcloudio/uni-app'
import tool from '@/pages/tabbar/user/utils/tool.vue'
import { getCouponsNum, getFootprintNum } from '@/api/members.js'
import { getUserWallet } from '@/api/members'
import configs from '@/config/config'
export default {
components: {
tool,
},
data() {
return {
configs,
userImage:configs.defaultUserPhoto,
coverTransform: "translateY(0px)",
coverTransition: "0s",
moving: false,
userInfo: {},
couponNum: "",
footNum: "",
walletNum: "",
};
},
onLoad() { },
onShow() {
this.userInfo = this.isLogin() || {};
if (this.isLogin("auth")) {
this.getUserOrderNum();
} else {
this.walletNum = 0;
this.couponNum = 0;
this.footNum = 0;
}
},
onPullDownRefresh() {
this.getUserOrderNum();
this.userInfo = this.isLogin();
},
// #ifndef MP
onNavigationBarButtonTap(e) {
const index = e.index;
if (index === 0) {
this.navigateTo("/pages/mine/set/setUp");
}
},
// #endif
import { useStore } from '@/store'
import { getThemeStyle } from '@/utils/theme'
import { isLogin, navigateToLogin, unitPrice } from '@/utils/filters.js'
mounted() { },
methods: {
/**
* 统一跳转接口,拦截未登录路由
* navigator标签现在默认没有转场动画所以用view
*/
navigateTo(url) {
uni.navigateTo({
url,
});
},
userDetail() {
this.userInfo.id
? this.navigateTo("/pages/mine/set/personMsg")
: this.navigateToLogin();;
},
async getUserOrderNum() {
uni.stopPullDownRefresh();
const store = useStore()
const themeStyle = computed(() => getThemeStyle(store.state.theme))
const lightColor = computed(() => store.getters.lightColor)
const mainColor = computed(() => store.getters.mainColor)
const aiderLightColor = computed(() => store.getters.aiderLightColor)
Promise.all([
getCouponsNum(), //优惠券
getFootprintNum(), //浏览数量
getUserWallet(), //预存款
]).then((res) => {
this.couponNum = res[0].data.result;
this.footNum = res[1].data.result;
this.walletNum = res[2].data.result.memberWallet;
});
},
},
};
const userImage = configs.defaultUserPhoto
const userInfo = ref<any>({})
const couponNum = ref<string | number>('')
const footNum = ref<string | number>('')
const walletNum = ref<string | number>('')
onLoad(() => {})
onShow(() => {
userInfo.value = isLogin() || {}
if (isLogin('auth')) {
getUserOrderNum()
} else {
walletNum.value = 0
couponNum.value = 0
footNum.value = 0
}
})
onPullDownRefresh(() => {
getUserOrderNum()
userInfo.value = isLogin()
})
// #ifndef MP
onNavigationBarButtonTap((e) => {
if (e.index === 0) {
navigateTo('/pages/mine/set/setUp')
}
})
// #endif
function navigateTo(url: string) {
uni.navigateTo({ url })
}
function userDetail() {
userInfo.value.id
? navigateTo('/pages/mine/set/personMsg')
: navigateToLogin()
}
async function getUserOrderNum() {
uni.stopPullDownRefresh()
Promise.all([
getCouponsNum(),
getFootprintNum(),
getUserWallet(),
]).then((res: any[]) => {
couponNum.value = res[0].data.result
footNum.value = res[1].data.result
walletNum.value = res[2].data.result.memberWallet
})
}
</script>
<style lang="scss" scoped>

View File

@@ -31,68 +31,68 @@
</view>
</template>
<script>
import {
getGoodsList
} from '@/api/goods.js';
export default {
data() {
return {
loadStatus: 'more',
params: {
pageNumber: 1,
pageSize: 10,
keyword: ''
},
goods: {},
goodsList: [],
nomsg: false,
};
},
methods: {
getList() {
uni.showLoading({
title: "加载中"
})
this.params.keyword = this.goods.goodsName;
getGoodsList(this.params).then(res => {
if (this.$store.state.isShowToast){ uni.hideLoading() }
if (res.statusCode == 200) {
let data = res.data;
if (data.data_total == 0) {
// this.nomsg = true;
this.loadStatus = 'noMore';
} else if (data.data_total < 10) {
this.loadStatus = 'noMore'
this.goodsList.push(...data.data)
} else {
this.goodsList.push(...data.data);
if (data.data.length < 10) this.loadStatus = 'noMore'
}
}
})
},
goDetail(item) {
uni.navigateTo({
url: '/pages/product/goods?id=' + item.id + "&goodsId=" +item.goodsId
})
},
loadData() {
if(this.loadStatus!='noMore'){
this.params.pageNumber++;
this.getList()
}
},
},
onLoad(option) {
this.goods = JSON.parse(decodeURIComponent(option.goods))
this.getList()
},
onReachBottom() { //触底事件,页面整个滚动使用
this.loadData()
}
}
<script setup lang="ts">
import { ref, reactive } from 'vue'
import { onLoad, onReachBottom } from '@dcloudio/uni-app'
import { getGoodsList } from '@/api/goods.js'
import { useStore } from '@/store'
import { unitPrice } from '@/utils/filters.js'
const store = useStore()
const loadStatus = ref('more')
const params = reactive({
pageNumber: 1,
pageSize: 10,
keyword: '',
})
const goods = ref<any>({})
const goodsList = ref<any[]>([])
const nomsg = ref(false)
function getList() {
uni.showLoading({ title: '加载中' })
params.keyword = goods.value.goodsName
getGoodsList(params).then((res) => {
if (store.state.isShowToast) {
uni.hideLoading()
}
if (res.statusCode == 200) {
const data = res.data
if (data.data_total == 0) {
loadStatus.value = 'noMore'
} else if (data.data_total < 10) {
loadStatus.value = 'noMore'
goodsList.value.push(...data.data)
} else {
goodsList.value.push(...data.data)
if (data.data.length < 10) loadStatus.value = 'noMore'
}
}
})
}
function goDetail(item: any) {
uni.navigateTo({
url: '/pages/product/goods?id=' + item.id + '&goodsId=' + item.goodsId,
})
}
function loadData() {
if (loadStatus.value != 'noMore') {
params.pageNumber++
getList()
}
}
onLoad((option) => {
goods.value = JSON.parse(decodeURIComponent(option.goods))
getList()
})
onReachBottom(() => {
loadData()
})
</script>
<style lang="scss" scoped>

View File

@@ -130,105 +130,98 @@
</view>
</template>
<script>
import { distribution } from "@/api/goods";
import configs from "@/config/config";
import storage from "@/utils/storage";
<script setup lang="ts">
import { ref } from 'vue'
import { distribution as fetchDistribution } from '@/api/goods'
import configs from '@/config/config'
import storage from '@/utils/storage'
import { tipsToLogin, setClipboard } from '@/utils/filters.js'
export default {
data() {
return {
configs,
storage,
repayingShow: false, //分销清退弹框
sharingShow: false,
sharingLink: ""
}
},
methods: {
handleNavigate(url) {
uni.navigateTo({
url,
});
},
inviter() {
if (storage.getUserInfo().id) {
this.sharingLink = this.configs.shareLink + "?inviter=" + this.storage.getUserInfo().id
this.sharingShow = true
} else {
uni.showToast({
title: "请先登录",
duration: 2000,
icon: "none",
});
}
},
navigateTo(url) {
const ignores = [
'/pages/mine/set/setUp',
'/pages/mine/set/editionIntro',
'/pages/mine/set/feedBack'
]
if (!ignores.includes(url)) {
if (this.tipsToLogin('normal')) {
this.handleNavigate(url)
}
}
else {
this.handleNavigate(url)
}
},
linkMsgDetail(){
if (this.tipsToLogin('normal')) {
uni.navigateTo({
url: '/pages/tabbar/home/title',
});
}
},
distribution() {
distribution().then((res) => {
if (res.data.result) {
let type = res.data.result.distributionStatus;
if (type == "PASS") {
uni.navigateTo({
url: "/pages/mine/distribution/home",
});
} else if (type == "REFUSE") {
uni.navigateTo({
url: "/pages/mine/distribution/auth",
});
} else if (type == "RETREAT") {
uni.showToast({
title: "您的分销资格已被清退。请联系管理员!",
duration: 2000,
icon: "none",
});
} else {
uni.showToast({
title: "您的信息正在审核",
duration: 2000,
icon: "none",
});
}
} else if (!res.data.success && res.data.code == 22000) {
uni.showToast({
title: "分销功能暂未开启",
duration: 2000,
icon: "none",
});
} else {
// 没有资格申请 先去实名认证
uni.navigateTo({
url: "/pages/mine/distribution/auth",
});
}
});
},
},
};
const sharingShow = ref(false)
const sharingLink = ref('')
function handleNavigate(url: string) {
uni.navigateTo({ url })
}
function inviter() {
if (storage.getUserInfo().id) {
sharingLink.value = configs.shareLink + '?inviter=' + storage.getUserInfo().id
sharingShow.value = true
} else {
uni.showToast({
title: '请先登录',
duration: 2000,
icon: 'none',
})
}
}
function getDetail(link: string) {
setClipboard(link)
}
function navigateTo(url: string) {
const ignores = [
'/pages/mine/set/setUp',
'/pages/mine/set/editionIntro',
'/pages/mine/set/feedBack',
]
if (!ignores.includes(url)) {
if (tipsToLogin('normal')) {
handleNavigate(url)
}
} else {
handleNavigate(url)
}
}
function linkMsgDetail() {
if (tipsToLogin('normal')) {
uni.navigateTo({
url: '/pages/tabbar/home/title',
})
}
}
function distribution() {
fetchDistribution().then((res) => {
if (res.data.result) {
const type = res.data.result.distributionStatus
if (type == 'PASS') {
uni.navigateTo({
url: '/pages/mine/distribution/home',
})
} else if (type == 'REFUSE') {
uni.navigateTo({
url: '/pages/mine/distribution/auth',
})
} else if (type == 'RETREAT') {
uni.showToast({
title: '您的分销资格已被清退。请联系管理员!',
duration: 2000,
icon: 'none',
})
} else {
uni.showToast({
title: '您的信息正在审核',
duration: 2000,
icon: 'none',
})
}
} else if (!res.data.success && res.data.code == 22000) {
uni.showToast({
title: '分销功能暂未开启',
duration: 2000,
icon: 'none',
})
} else {
uni.navigateTo({
url: '/pages/mine/distribution/auth',
})
}
})
}
</script>
<style lang="scss" scoped>