ifcheng 2 years ago
parent
commit
cd99dfab19
5 changed files with 34 additions and 9 deletions
  1. 19 0
      src/filters/index.ts
  2. 2 0
      src/main.ts
  3. 5 3
      src/pages/account/index.vue
  4. 5 5
      src/pages/benefits/index.vue
  5. 3 1
      src/pages/gift-card/index.vue

+ 19 - 0
src/filters/index.ts

@@ -0,0 +1,19 @@
+import { App } from 'vue'
+
+export function formatDate(value: string) {
+  return value.split(' ')[0].replace(/-/g, '/')
+}
+
+const filters = { formatDate }
+
+export default {
+  install(app: App) {
+    app.config.globalProperties.$filters = filters
+  },
+}
+
+declare module '@vue/runtime-core' {
+  interface ComponentCustomProperties {
+    $filters: typeof filters
+  }
+}

+ 2 - 0
src/main.ts

@@ -9,9 +9,11 @@ import './utils/third-login'
 
 import Toast from './components/toast'
 import Dialog from './components/dialog'
+import globalFilters from './filters'
 
 getUserInfo(false).finally(() => {
   const app = createApp(App)
   app.use(router).mount('#app')
   app.use(Toast).use(Dialog)
+  app.use(globalFilters)
 })

+ 5 - 3
src/pages/account/index.vue

@@ -144,15 +144,17 @@ const { values, handleSubmit } = useForm<ApiUser.Update.Request>({
     mobile: state.userInfo?.mobile,
   },
   schema: {
-    name: string().required(),
-    mobile: string().required(),
+    name: string().required('Please enter your real name'),
+    mobile: string().required('Please enter your phone number'),
   },
 })
 
 watch(status, () => window.scrollTo(0, 0))
 
 async function applyUpdate() {
-  values.address = address.value.filter(Boolean).join(',')
+  if (!(address.value.length === 3 && address.value.every(Boolean)))
+    return Toast('Please enter your full address')
+  values.address = address.value.join(',')
   await updateUserInfo(values as any)
   Toast('success')
   status.value = 0

+ 5 - 5
src/pages/benefits/index.vue

@@ -87,24 +87,24 @@ export default defineComponent({
           return ''
       }
     },
-    onClickButton(right) {
+    onClickButton(item) {
       switch (+item.type) {
         case 1:
           return +item.need_apply
-            ? this.$router.push(`/repaire/appointment?right_id=${right.id}`)
+            ? this.$router.push(`/repaire/appointment?right_id=${item.id}`)
             : 'Nearby shops'
         case 2:
           return item.button_type === 'contact_us'
             ? 'Contact us'
-            : item.button_type && (location.href = right.button_link)
+            : item.button_type && (location.href = item.button_link)
         case 4:
           return +item.receive_method === 2
             ? 'Nearby shops'
             : this.$router.push({
                 path: '/mailing',
                 query: {
-                  right_id: right.id,
-                  right_name: right.title,
+                  right_id: item.id,
+                  right_name: item.title,
                 },
               })
         default:

+ 3 - 1
src/pages/gift-card/index.vue

@@ -38,7 +38,9 @@
           >
             <p class="card-title">{{ item.title }}</p>
             <p class="card-period">
-              Validity: {{ item.used_at }}-{{ item.expired_at }}
+              Validity: {{ $filters.formatDate(item.created_at) }}-{{
+                $filters.formatDate(item.expired_at)
+              }}
             </p>
             <p class="card-value">
               - {{ item.gift_card_amount }}