From 150ab7d9d454b8108dc471e4fb4383bab20f3f2a Mon Sep 17 00:00:00 2001 From: Wayne Date: Fri, 5 Apr 2024 16:14:56 +0800 Subject: [PATCH] 0001061 --- src/router/index.js | 12 +- src/views/Auth/Edit.vue | 1038 ---------------------------------- src/views/Auth/GetAuth.vue | 4 +- src/views/Card/Edit.vue | 83 ++- src/views/Register/index.vue | 17 +- 5 files changed, 75 insertions(+), 1079 deletions(-) delete mode 100644 src/views/Auth/Edit.vue diff --git a/src/router/index.js b/src/router/index.js index fd28cfa..a63ff10 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -95,12 +95,12 @@ const routes = [ component: () => import("../views/Auth/GetAuth.vue"), meta: { keepAlive: true }, }, - { - path: "/auth/edit", - name: "AuthEdit", - component: () => import("../views/Auth/Edit.vue"), - meta: { keepAlive: true }, - }, + // { + // path: "/auth/edit", + // name: "AuthEdit", + // component: () => import("../views/Auth/Edit.vue"), + // meta: { keepAlive: true }, + // }, { path: "/auth/preview", name: "AuthPreview", diff --git a/src/views/Auth/Edit.vue b/src/views/Auth/Edit.vue deleted file mode 100644 index 2859148..0000000 --- a/src/views/Auth/Edit.vue +++ /dev/null @@ -1,1038 +0,0 @@ - - - - - diff --git a/src/views/Auth/GetAuth.vue b/src/views/Auth/GetAuth.vue index 3ce2752..29c0142 100644 --- a/src/views/Auth/GetAuth.vue +++ b/src/views/Auth/GetAuth.vue @@ -14,7 +14,7 @@ onMounted(async()=>{ }) const handleEdit = (user_id)=>{ - router.push({path:'/auth/edit',query:{user_id: user_id}}); + router.push({path:'/card',query:{user_id: user_id}}); } @@ -44,7 +44,7 @@ const handleEdit = (user_id)=>{ {{v.user_id}} {{v.auth_time}} - 刪除 + 編輯 diff --git a/src/views/Card/Edit.vue b/src/views/Card/Edit.vue index b09be4c..cab2447 100644 --- a/src/views/Card/Edit.vue +++ b/src/views/Card/Edit.vue @@ -2,23 +2,24 @@ import Footer from "@/components/Footer.vue"; import FlexView from "@/components/FlexView.vue"; -import { ref, watch, computed, nextTick } from "vue"; +import { ref, onMounted , watch, computed, nextTick } from "vue"; import { useCardStore } from '@/store/card' -import { useRouter } from "vue-router"; +import { useRouter,useRoute } from "vue-router"; import axios from "axios"; import _ from "lodash"; import { showToast, showLoadingToast, showSuccessToast, showFailToast } from "vant"; -import { onMounted } from "vue"; +import { getCusCard, updateCusCard } from "@/api"; const URL = window.URL || window.webkitURL; const cardStore = useCardStore(); +const route = useRoute(); const router = useRouter(); const showNfc = ref(false); @@ -82,11 +83,25 @@ const defaultTheme = { isShow: true } - -onMounted(() => { - if (cardStore.cusCard.cus_card && cardStore.cusCard.cus_card.length > 0) { - form.value = JSON.parse(cardStore.cusCard.cus_card); +const userid = ref(route.query.user_id || null) + +onMounted(async () => { + + // 判斷query參數是否有userid + if(userid.value){ + let res = await getCusCard( {userid: userid.value} ) + + if(res.code===200){ + if(res.data.cus_card && res.data.cus_card.length>0){ + form.value = JSON.parse(res.data.cus_card) + } + } + }else{ + if (cardStore.cusCard.cus_card && cardStore.cusCard.cus_card.length > 0) { + form.value = JSON.parse(cardStore.cusCard.cus_card); + } } + }); const sizeColumns = ref([ @@ -355,7 +370,13 @@ const onDescSizeConfirm = ({ selectedOptions }) => { }; const handleSubmit = async () => { - let user_id = sessionStorage.getItem("uid"); + let user_id; + + if(!userid.value){ + user_id= sessionStorage.getItem("uid"); + }else{ + user_id = userid.value; + } showLoadingToast({ duration: 0, @@ -367,31 +388,43 @@ const handleSubmit = async () => { card_title: form.value.title, show_cus: form.value.showNfc, cus_card: JSON.stringify(form.value), + user_id: user_id, }; - let res = cardStore.updateCusCard(cusCard); - - if (res) { - showSuccessToast("建立成功"); - } else { - showFailToast("建立失敗"); + if(!userid.value){ + let res = cardStore.updateCusCard(cusCard); + if (res) { + showSuccessToast("建立成功"); + } else { + showFailToast("建立失敗"); + } + router.push("/card"); + + }else{ + let res = await updateCusCard(cusCard); + if (res.code === 200) { + showSuccessToast("建立成功"); + } else { + showFailToast("建立失敗"); + } + router.push("/auth/getauth"); } - // let res = await updateCusCard(cusCard); +}; - // if (res.code === 200) { - // cardStore.cusCard = cusCard; - // showSuccessToast("建立成功"); - // } else { - // showToast.fail("建立失敗"); - // } - router.push("/card"); +const goBack = () => { + if(!userid.value){ + router.push('/') + }else{ + router.push('/auth/getauth') + } }; +