Explorar el Código

userform修改

zhoujump hace 1 mes
padre
commit
3d85b1fd7e
Se han modificado 4 ficheros con 59 adiciones y 42 borrados
  1. 1 9
      src/App.vue
  2. 9 0
      src/layout/index.vue
  3. 7 3
      src/router/index.js
  4. 42 30
      src/views/user/form.vue

+ 1 - 9
src/App.vue

@@ -40,20 +40,11 @@ export default {
   },
   mounted() {
     this.initStore()
-    this.refreshUser()
     this.$bus.$on('showPacket', (val) => {
       this.showPacket = val
     })
   },
   methods: {
-    refreshUser() {
-      this.$store.dispatch('refreshToken').then((res) => {
-      }).catch(err => {
-        this.$router.push({
-          name: 'login'
-        })
-      })
-    },
     initStore() {
       window.addEventListener('beforeunload', () => {
         localStorage.setItem('store', JSON.stringify(this.$store.state))
@@ -69,6 +60,7 @@ export default {
         this.refreshRoute()
       })
       this.$router.beforeEach((to, from, next) => {
+        console.log(to)
         if (router.app.$store.getters.token) {
           if (router.app.$store.getters.user.isAdmin) {
             this.isAnimation = true

+ 9 - 0
src/layout/index.vue

@@ -116,8 +116,17 @@ export default {
   },
   mounted() {
     this.getPacket()
+    this.refreshUser()
   },
   methods: {
+    refreshUser() {
+      this.$store.dispatch('refreshToken').then((res) => {
+      }).catch(err => {
+        this.$router.push({
+          name: 'login'
+        })
+      })
+    },
     getPacket() {
       try {
         const appList = this.user.app_list

+ 7 - 3
src/router/index.js

@@ -532,9 +532,13 @@ router.beforeEach((to, from, next) => {
     if (res) {
       next()
     } else {
-      next({
-        name: '401'
-      })
+      if (to.name === 'login' || to.name === 'userRegister' || to.name === 'userForm' || to.name === 'thirdLogin') {
+        next()
+      } else {
+        next({
+          name: '401'
+        })
+      }
     }
   })
 })

+ 42 - 30
src/views/user/form.vue

@@ -35,7 +35,10 @@ export default Vue.extend({
   methods: {
     init() {
       this.expo_key = this.$route.params.url
-      if (this.token) {
+      const form_data = sessionStorage.getItem('form_cache')
+      if (form_data) {
+        this.from_data = JSON.parse(form_data)
+      } else {
         getExpoInfo(this.expo_key).then(res => {
           this.from_data = res.data
           this.from_data.form_fields.forEach(item => {
@@ -46,13 +49,6 @@ export default Vue.extend({
           this.expo_id = res.data.id
         }).catch(err => {
         })
-      } else {
-        this.$router.push({
-          name: 'userRegister',
-          query: {
-            expo_key: this.expo_key
-          }
-        })
       }
     },
     share(way) {
@@ -106,30 +102,47 @@ export default Vue.extend({
       })
     },
     submit() {
-      if (this.loading) {
-        return
-      }
-      this.loading = true
-      const form_data = {}
-      for (let i = 0; i < this.from_data.form_fields.length; i++) {
-        if (this.from_data.form_fields[i].field_name) {
-          form_data[this.from_data.form_fields[i].field_name] = this.from_data.form_fields[i].value
-        } else {
-          form_data['field_' + this.from_data.form_fields[i].id] = this.from_data.form_fields[i].value
+      if (this.token) {
+        if (this.loading) {
+          return
         }
+        this.loading = true
+        const form_data = {}
+        for (let i = 0; i < this.from_data.form_fields.length; i++) {
+          if (this.from_data.form_fields[i].field_name) {
+            form_data[this.from_data.form_fields[i].field_name] = this.from_data.form_fields[i].value
+          } else {
+            form_data['field_' + this.from_data.form_fields[i].id] = this.from_data.form_fields[i].value
+          }
 
-        if (this.from_data.form_fields[i].is_required && !this.from_data.form_fields[i].value) {
-          this.$message.error('请填写必填项')
-          this.loading = false
-          return
+          if (this.from_data.form_fields[i].is_required && !this.from_data.form_fields[i].value) {
+            this.$message.error('请填写必填项')
+            this.loading = false
+            return
+          }
         }
+        submitForm(this.expo_id, form_data).then(res => {
+          this.isOk = true
+          this.loading = false
+        }).catch(err => {
+          this.loading = false
+        })
+      } else {
+        this.$confirm('请先登录', '提示', {
+          type: 'warning',
+          callback: action => {
+            if (action === 'confirm') {
+              sessionStorage.setItem('form_cache', JSON.stringify(this.from_data))
+              this.$router.push({
+                name: 'userRegister',
+                query: {
+                  expo_key: this.expo_key
+                }
+              })
+            }
+          }
+        })
       }
-      submitForm(this.expo_id, form_data).then(res => {
-        this.isOk = true
-        this.loading = false
-      }).catch(err => {
-        this.loading = false
-      })
     },
     returnWidth(name) {
       if (['email', 'address'].includes(name)) {
@@ -297,8 +310,7 @@ export default Vue.extend({
       <div v-if="from_data.show_official_footer" class="power-by">
         <a target="_blank" href="/">多果表单</a>提供技术支持 by <a target="_blank" href="https://matchexpo.cn/">MatchExpo</a>
       </div>
-      <div v-else class="power-by">
-      </div>
+      <div v-else class="power-by" />
       <div class="share">
         <div class="text">分享至:</div>
         <div class="share-list">