一些优化

This commit is contained in:
haomingming
2025-09-04 17:34:47 +08:00
parent b068fb00cc
commit 4659f30400
18 changed files with 508 additions and 87 deletions
+6 -10
View File
@@ -295,17 +295,14 @@
<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
import course_api from "@/api/course_api.js"
import { onLoad } from '@dcloudio/uni-app'
const courseId = ref(0)
onMounted(() => {
// 获取页面参数
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
const options = currentPage.options || {}
courseId.value = options.id
console.log('课程ID:', options.id)
onLoad((options) => {
courseId.value = options.id // 已支持 App-Plus
console.log('课程ID:', options.id)
})
const courseId = ref(0)
// 响应式数据
@@ -762,7 +759,6 @@ const updatePageData = (data) => {
}
}
// 生命周期
onMounted(() => {
getSystemInfo()
startCountdown()
+8 -7
View File
@@ -146,6 +146,8 @@
<script setup>
import { ref, onMounted } from 'vue'
import course_api from '@/api/course_api'
import { onLoad } from '@dcloudio/uni-app'
// 响应式数据
const statusBarHeight = ref(0)
@@ -327,18 +329,17 @@ const onSortChange = (e) => {
filterCourses()
}
// 生命周期
onMounted(() => {
// 获取页面参数
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
const options = currentPage.options || {}
onLoad((options) => {
type_id.value = options.type
special_type.value = options.special_type
special_name.value = options.special_name
console.log('特殊类型ID:', options.special_type)
console.log('类型ID:', options.type)
})
// 生命周期
onMounted(() => {
getSystemInfo()
if(type_id.value > 0){
getSecondType()
+27 -12
View File
@@ -90,6 +90,10 @@ import { ref, onMounted, computed } from 'vue'
import course_api from "@/api/course_api.js"
import { requestPayment } from '@/utils/payment.js'
import { onLoad } from '@dcloudio/uni-app'
// 响应式数据
const statusBarHeight = ref(0)
const navBarHeight = ref(88)
@@ -201,14 +205,27 @@ const confirmPayment = () => {
return
}
order_pay_type.value = computeOrderPayType()
console.log('确认支付,支付方式:', { usePoints: usePoints.value, useBalance: useBalance.value, order_pay_type: order_pay_type.value })
let openid = ""
if (process.env.NODE_ENV === 'development') {
openid = uni.getStorageSync('DEV_APPID');
} else {
openid = uni.getStorageSync('AUTH_APPID');
if (process.env.UNI_PLATFORM == "h5") {
if (process.env.NODE_ENV === 'development') {
openid = uni.getStorageSync('DEV_APPID');
} else {
openid = uni.getStorageSync('AUTH_APPID');
}
} else if(process.env.UNI_PLATFORM == "mp-weixin") {
const {
envVersion
} = uni.getAccountInfoSync().miniProgram;
if (envVersion == "release") {
openid = uni.getStorageSync('DEV_APPID');
} else {
openid = uni.getStorageSync('AUTH_APPID');
}
}else{
//app
}
course_api.createExcellencourseMixedOrder(courseId.value, order_pay_type.value, openid).then(res => {
console.log('创建订单:', res)
@@ -313,15 +330,13 @@ const updatePaymentMethod = () => {
}
}
onLoad((options) => {
courseId.value = options.id // 已支持 App-Plus
console.log('课程ID:', options.id)
})
// 生命周期
onMounted(() => {
// 获取页面参数
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
const options = currentPage.options || {}
courseId.value = options.id
console.log('课程ID:', options.id)
getSystemInfo()
getCourseInfo()
})
+8 -7
View File
@@ -63,6 +63,8 @@
<script setup>
import { ref, onMounted } from 'vue'
import course_api from "@/api/course_api.js"
import { onLoad } from '@dcloudio/uni-app'
// 响应式数据
const statusBarHeight = ref(0)
@@ -150,18 +152,17 @@ const goBack = () => {
uni.navigateBack()
}
// 生命周期
onMounted(() => {
getSystemInfo()
// 获取页面参数
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
const options = currentPage.options || {}
onLoad((options) => {
is_commented.value = options.is_commented
courseId.value = options.id
console.log('课程ID:', options.id)
})
// 生命周期
onMounted(() => {
getSystemInfo()
})
</script>
<style lang="scss">
@@ -122,6 +122,7 @@
<script setup>
import { ref, onMounted } from 'vue'
import course_api from "@/api/course_api.js"
import { onLoad } from '@dcloudio/uni-app'
const invoice_id = ref('')
@@ -312,15 +313,14 @@ const loadInvoiceData = () => {
})
}
onLoad((options) => {
invoice_id.value = options.invoice_id // 已支持 App-Plus
console.log('发票ID:', options.invoice_id)
})
onMounted(() => {
getSystemInfo()
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
const options = currentPage.options || {}
invoice_id.value = options.invoice_id
if (!invoice_id.value) {
hasError.value = true
isLoading.value = false
+201 -19
View File
@@ -67,8 +67,8 @@
</view>
<!-- 剩余时间(仅未支付订单显示) -->
<view class="remaining-time" v-if="order.remainingTime && activeTab === 'unpaid'">
<text class="time-text">剩余时间: {{ order.remainingTime }}</text>
<view class="remaining-time" v-if="order.expire_time && activeTab === 'unpaid'">
<text class="time-text">剩余时间: {{ countdownDisplay[order.id] || formatCountdown(order.expire_time) }}</text>
</view>
<!-- 操作按钮 -->
@@ -105,8 +105,9 @@
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { ref, computed, onMounted, onUnmounted } from 'vue'
import course_api from "@/api/course_api.js"
import { requestPayment } from "@/utils/payment.js"
// 响应式数据
const statusBarHeight = ref(0)
@@ -114,6 +115,10 @@ const navBarHeight = ref(88)
const activeTab = ref('paid') // 默认激活"已支付"标签
// 订单数据
const orderList = ref([])
// 倒计时定时器
const countdownTimer = ref(null)
// 倒计时显示数据
const countdownDisplay = ref({})
// 计算属性
const currentOrderList = computed(() => {
@@ -136,7 +141,70 @@ const goBack = () => {
uni.navigateBack()
}
// 倒计时计算函数
const formatCountdown = (timestamp) => {
if (!timestamp) return ''
const now = Math.floor(Date.now() / 1000) // 当前时间戳(秒)
const expireTime = parseInt(timestamp) // 过期时间戳(秒)
const remainingSeconds = expireTime - now
if (remainingSeconds <= 0) {
return '已过期'
}
const days = Math.floor(remainingSeconds / 86400)
const hours = Math.floor((remainingSeconds % 86400) / 3600)
const minutes = Math.floor((remainingSeconds % 3600) / 60)
const seconds = remainingSeconds % 60
if (days > 0) {
return `${days}天${hours.toString().padStart(2, '0')}小时${minutes.toString().padStart(2, '0')}分钟`
} else if (hours > 0) {
return `${hours}小时${minutes.toString().padStart(2, '0')}分钟${seconds.toString().padStart(2, '0')}秒`
} else if (minutes > 0) {
return `${minutes}分钟${seconds.toString().padStart(2, '0')}秒`
} else {
return `${seconds}秒`
}
}
// 更新所有订单的倒计时显示
const updateCountdownDisplay = () => {
const currentList = orderList.value[activeTab.value] || []
currentList.forEach(order => {
if (order.expire_time) {
countdownDisplay.value[order.id] = formatCountdown(order.expire_time)
}
})
}
// 启动倒计时定时器
const startCountdown = () => {
if (countdownTimer.value) {
clearInterval(countdownTimer.value)
}
// 立即更新一次倒计时显示
updateCountdownDisplay()
countdownTimer.value = setInterval(() => {
updateCountdownDisplay()
}, 1000)
}
// 停止倒计时定时器
const stopCountdown = () => {
if (countdownTimer.value) {
clearInterval(countdownTimer.value)
countdownTimer.value = null
}
}
const switchTab = (tab) => {
// 停止当前倒计时
stopCountdown()
activeTab.value = tab
console.log('切换到标签:', tab)
getOrderList()
@@ -157,12 +225,14 @@ const copyOrderNumber = (orderNumber) => {
const getSecondaryButtonText = (status) => {
switch (status) {
case 'pending':
case 'created':
return '取消订单'
case 'timeout':
case 'overtime':
return '支付超时'
case 'failed':
return '支付失败'
case 'canceled':
return '已取消'
default:
return '查看订单'
}
@@ -170,11 +240,13 @@ const getSecondaryButtonText = (status) => {
const getPrimaryButtonText = (status) => {
switch (status) {
case 'pending':
return '继续支付'
case 'timeout':
case 'canceled':
return '已取消'
case 'overtime':
case 'failed':
return '查看课程'
case 'created':
return '继续支付'
default:
return '进入学习'
}
@@ -182,7 +254,7 @@ const getPrimaryButtonText = (status) => {
const handleSecondaryAction = (order) => {
switch (order.status) {
case 'pending':
case 'created':
cancelOrder(order)
break
case 'timeout':
@@ -196,7 +268,7 @@ const handleSecondaryAction = (order) => {
const handlePrimaryAction = (order) => {
switch (order.status) {
case 'pending':
case 'created':
continuePayment(order)
break
case 'timeout':
@@ -214,11 +286,8 @@ const cancelOrder = (order) => {
content: '确定要取消这个订单吗?',
success: (res) => {
if (res.confirm) {
uni.showToast({
title: '订单已取消',
icon: 'success'
})
// 这里可以调用API取消订单
// 调用取消订单接口
cancelExcellencourseOrder(order)
}
}
})
@@ -226,9 +295,8 @@ const cancelOrder = (order) => {
const continuePayment = (order) => {
console.log('继续支付订单:', order.id)
uni.navigateTo({
url: '/pages_course/course_payment/course_payment'
})
// 调用继续支付接口
payExcellencourseOrderContinue(order)
}
const viewCourse = (order) => {
@@ -290,11 +358,20 @@ const getOrderList = () => {
balancePayment: balanceCents > 0 ? toYuan(balanceCents) : null,
pointsPayment: points > 0 ? points : null,
actualPayment: toYuan(item.pay_account),
status: item.order_status === 'paid' ? 'paid' : 'created'
status: item.order_status,
expire_time: item.expire_time // 保持原始时间戳格式
}
})
orderList.value[activeTab.value] = mapped
// 清空倒计时显示数据
countdownDisplay.value = {}
// 如果有未支付订单,启动倒计时
if (activeTab.value === 'unpaid' && mapped.length > 0) {
startCountdown()
}
} else {
uni.showToast({ title: res.msg || '获取订单失败', icon: 'none' })
}
@@ -303,11 +380,116 @@ const getOrderList = () => {
})
}
const payExcellencourseOrderContinue = (order) => {
// 显示加载提示
uni.showLoading({ title: '处理中...' })
let openid = ""
if (process.env.UNI_PLATFORM == "h5") {
if (process.env.NODE_ENV === 'development') {
openid = uni.getStorageSync('DEV_APPID');
} else {
openid = uni.getStorageSync('AUTH_APPID');
}
} else if(process.env.UNI_PLATFORM == "mp-weixin") {
const {
envVersion
} = uni.getAccountInfoSync().miniProgram;
if (envVersion == "release") {
openid = uni.getStorageSync('DEV_APPID');
} else {
openid = uni.getStorageSync('AUTH_APPID');
}
}else{
//app
}
course_api.payExcellencourseOrderContinue(order.id, openid).then(res => {
console.log('继续支付订单:', res)
uni.hideLoading()
if (res.code == 200) {
const payParams = res.data.order
console.log(payParams)
requestPayment(
payParams,
// 支付成功
(res) => {
uni.showToast({ title: '支付成功', icon: 'success' })
// 可以跳转到支付成功页,或者查询订单状态
getOrderList()
},
// 支付失败
(err) => {
console.error('支付失败', err)
uni.showToast({ title: '支付失败或取消', icon: 'none' })
}
)
} else {
uni.showToast({
title: res.msg || '继续支付失败',
icon: 'none',
duration: 3000
})
}
}).catch(err => {
uni.hideLoading()
console.error('继续支付订单失败:', err)
uni.showToast({
title: '网络错误,请重试',
icon: 'none',
duration: 3000
})
})
}
const cancelExcellencourseOrder = (order) => {
// 显示加载提示
uni.showLoading({ title: '取消中...' })
course_api.cancelExcellencourseOrder(order.id).then(res => {
console.log('取消订单:', res)
uni.hideLoading()
if (res.code == 200) {
uni.showToast({
title: '订单已取消',
icon: 'success',
duration: 2000
})
// 成功后刷新订单列表
setTimeout(() => {
getOrderList()
}, 1500)
} else {
uni.showToast({
title: res.msg || '取消订单失败',
icon: 'none',
duration: 3000
})
}
}).catch(err => {
uni.hideLoading()
console.error('取消订单失败:', err)
uni.showToast({
title: '网络错误,请重试',
icon: 'none',
duration: 3000
})
})
}
// 生命周期
onMounted(() => {
getSystemInfo()
getOrderList()
})
onUnmounted(() => {
stopCountdown()
})
</script>
<style lang="scss">