细节优化
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<script setup>
|
||||
import { ref, onMounted } from "vue";
|
||||
import { ref, onMounted, onUnmounted } from "vue";
|
||||
import Container from "@/components/Container.vue";
|
||||
import SButton from "@/components/SButton.vue";
|
||||
import { payOrderAPI, cancelOrderListAPI, getHomeData } from "@/apis";
|
||||
import { orderStatusNames, getStatusColor } from "@/constants";
|
||||
import { orderStatusNames, getStatusColor, MESSAGETYPES } from "@/constants";
|
||||
import useStore from "@/store";
|
||||
const store = useStore();
|
||||
const { updateUser } = store;
|
||||
@@ -11,9 +11,27 @@ const { updateUser } = store;
|
||||
const data = ref({});
|
||||
const loading = ref(false);
|
||||
|
||||
async function onReceiveMessage(messages = []) {
|
||||
messages.forEach((msg) => {
|
||||
if (
|
||||
msg.constructor === MESSAGETYPES.PaySuccess &&
|
||||
data.value.orderId === msg.orderID
|
||||
) {
|
||||
data.value.orderStatus = 4;
|
||||
data.value.paymentTime = msg.payTime;
|
||||
uni.setStorageSync("order", data.value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
const order = uni.getStorageSync("order");
|
||||
data.value = order || {};
|
||||
uni.$on("socket-inbox", onReceiveMessage);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
uni.$off("socket-inbox", onReceiveMessage);
|
||||
});
|
||||
|
||||
const goPay = async () => {
|
||||
@@ -46,6 +64,7 @@ const goPay = async () => {
|
||||
const cancelOrder = async () => {
|
||||
const result = await cancelOrderListAPI(data.value.orderId);
|
||||
data.value = result;
|
||||
uni.setStorageSync("order", result);
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user