Bläddra i källkod

订座-登录页接口对接

panyong 3 år sedan
förälder
incheckning
7cb089960a

+ 18 - 3
htmldev/dashboard/package-lock.json

@@ -8776,9 +8776,9 @@
       }
     },
     "lodash": {
-      "version": "4.17.20",
-      "resolved": "https://registry.npm.taobao.org/lodash/download/lodash-4.17.20.tgz?cache=0&sync_timestamp=1597336082988&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Flodash%2Fdownload%2Flodash-4.17.20.tgz",
-      "integrity": "sha1-tEqbYpe8tpjxxRo1RaKzs2jVnFI=",
+      "version": "4.17.21",
+      "resolved": "https://registry.npm.taobao.org/lodash/download/lodash-4.17.21.tgz",
+      "integrity": "sha1-Z5WRxWTDv/quhFTPCz3zcMPWkRw=",
       "dev": true
     },
     "lodash.defaults": {
@@ -13249,6 +13249,12 @@
       "integrity": "sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=",
       "dev": true
     },
+    "tiny-cookie": {
+      "version": "1.0.1",
+      "resolved": "https://registry.npm.taobao.org/tiny-cookie/download/tiny-cookie-1.0.1.tgz",
+      "integrity": "sha1-dTeGB5xkKjw9CyrMrWAPjeEZrCo=",
+      "dev": true
+    },
     "tiny-emitter": {
       "version": "2.1.0",
       "resolved": "https://registry.npm.taobao.org/tiny-emitter/download/tiny-emitter-2.1.0.tgz",
@@ -13801,6 +13807,15 @@
         "swiper": "^4.0.7"
       }
     },
+    "vue-cookie": {
+      "version": "1.1.4",
+      "resolved": "https://registry.npm.taobao.org/vue-cookie/download/vue-cookie-1.1.4.tgz",
+      "integrity": "sha1-uLRtESvan5Oi9HAXwu1SgtIGT9o=",
+      "dev": true,
+      "requires": {
+        "tiny-cookie": "^1.0"
+      }
+    },
     "vue-eslint-parser": {
       "version": "7.1.0",
       "resolved": "https://registry.npm.taobao.org/vue-eslint-parser/download/vue-eslint-parser-7.1.0.tgz",

+ 2 - 0
htmldev/dashboard/package.json

@@ -31,6 +31,7 @@
     "eslint-plugin-vue": "^6.2.2",
     "express": "^4.17.1",
     "filemanager-webpack-plugin": "^2.0.5",
+    "lodash": "^4.17.21",
     "node-sass": "^4.14.1",
     "path": "^0.12.7",
     "postcss-pxtorem": "^5.1.1",
@@ -42,6 +43,7 @@
     "style-resources-loader": "^1.3.3",
     "vant": "^2.10.9",
     "vue-awesome-swiper": "^3.1.3",
+    "vue-cookie": "^1.1.4",
     "vue-router": "3.0.7",
     "vue-template-compiler": "^2.6.11",
     "vuex": "^3.5.1",

+ 6 - 38
htmldev/dashboard/src/api/common.js

@@ -1,34 +1,13 @@
 import request from './request'
 
-/*
-* 获取区域信息
-* */
-export const getChinaArea = () => request({
-  method: 'GET',
-  url: '/area'
-})
-
-/*
-* 获取网点列表
-* */
-export const getBankList = (id) => request({
-  method: 'GET',
-  url: '/home/bank/bankList',
-  params: {
-    id
-  }
-})
-
 /*
 * 短信发送
 * */
-export const sendSMS = (cellphone, type = 0, captcha) => request({
-  method: 'GET',
-  url: '/sendMsg',
-  params: {
-    cellphone,
-    type,
-    captcha
+export const sendSMS = (phone) => request({
+  method: 'POST',
+  url: '/api/v1/send/code',
+  data: {
+    phone
   }
 })
 
@@ -40,17 +19,6 @@ export const uploadFile = (formData) => request({
     'Content-Type': 'multipart/form-data'
   },
   method: 'POST',
-  url: '/upload',
+  url: '/v1/upload/file',
   data: formData
 })
-
-/*
-* 获取产品信息
-* */
-export const getProductDetail = (id) => request({
-  method: 'GET',
-  url: '/home/product/detail',
-  params: {
-    id
-  }
-})

+ 5 - 9
htmldev/dashboard/src/api/request.js

@@ -1,8 +1,10 @@
+import Vue from 'vue'
 import axios from 'axios'
 import router from '../router'
 
-const host = window.location.host
-const domain = host.substring(0, host.indexOf('.')) || host.substring(0, host.indexOf(':'))
+const getCookieValue = (name) => {
+  return Object.prototype.toString.call(Vue.cookie.get(name)) === '[object Null]' ? '' : Vue.cookie.get(name)
+}
 const request = axios.create({
   withCredentials: true,
   baseURL: process.env.API_DOMAIN,
@@ -14,13 +16,7 @@ const request = axios.create({
 
 // Add a request interceptor
 request.interceptors.request.use(request => {
-  const requestUrl = request.url
-  // Do something before request is sent
-  request.url = requestUrl + (requestUrl.indexOf('?') > -1 ? '&' : '?') + 'next=' + encodeURIComponent(location.href)
-  // 因为微信开发者工具重复授权,本地开发时写死
-  if (/^(0|192|10|localhost)|(test$)/.test(domain)) {
-    request.url += '&owner_open_id=o0wUBtDVDAvu3z1GRu58kv4_9DnI'
-  }
+  request.headers.token = getCookieValue('token')
   return request
 }, error => {
   // Do something with request error

+ 3 - 3
htmldev/dashboard/src/login/api/index.js

@@ -1,10 +1,10 @@
 import request from '@/api/request'
 
-export const partnerLogin = (partnerPhone, code) => request({
+export const login = (phone, code) => request({
   method: 'POST',
-  url: '/partner/login',
+  url: '/api/v1/user/login',
   data: {
-    partnerPhone,
+    phone,
     code
   }
 })

+ 79 - 56
htmldev/dashboard/src/login/index.vue

@@ -1,30 +1,62 @@
 <template>
   <div class="wrapper">
-    <img class="logo" src="./image/logo@2x.png" alt="">
+    <img
+      class="logo"
+      src="./image/logo@2x.png" alt="">
     <ul class="form-wrap">
       <li>
         <label>
-          <span v-for="(str, index) in '+86'" :key="index">{{ str }}</span>
+          <span
+            v-for="(str, index) in '+86'"
+            :key="index">{{ str }}</span>
         </label>
         <div class="value-wrap">
-          <input type="tel" placeholder="请输入手机号码" v-myBlur v-model.trim="postData.partnerPhone" @input="funLimitLength">
+          <input
+            type="tel"
+            placeholder="请输入手机号码"
+            v-myBlur
+            v-model.trim="postData.phone"
+            @input="funLimitLength">
         </div>
       </li>
       <li>
         <div class="value-wrap">
-          <input type="tel" placeholder="请输入短信验证码" v-myBlur v-model.trim="postData.code" @input="funLimitLength">
+          <input
+            type="tel"
+            placeholder="请输入短信验证码"
+            v-myBlur
+            v-model.trim="postData.code"
+            @input="funLimitLength">
         </div>
-        <button class="get-code" @click="funGetCode">{{[0, 60].includes(numCount) ? '获取验证码' : numCount + '秒'}}</button>
+        <button
+          class="get-code"
+          @click="funGetCode">{{[0, 60].includes(numCount) ? '获取验证码' : numCount + '秒'}}
+        </button>
       </li>
     </ul>
-    <button class="submit" @click="funSubmit">登 录</button>
+    <button
+      class="submit"
+      @click="funSubmit">登 录
+    </button>
     <div class="footer">
-      <van-checkbox v-model="checked"></van-checkbox>
+      <van-checkbox
+        v-model="checked"
+        checked-color="#D32323"></van-checkbox>
       <p class="tip-text">
-        <span class="label" v-for="(str, index) in '登录听邦即代表您已同意'" :key="'a' + index">{{ str }}</span>
-        <span class="value" v-for="(str, index) in '《用户协议》'" :key="'b' + index">{{ str }}</span>
-        <span class="label">与</span>
-        <span class="value" v-for="(str, index) in '《隐私协议》'" :key="'c' + index">{{ str }}</span>
+        <span
+          class="label"
+          v-for="(str, index) in '登录听邦即代表您已同意'"
+          :key="'a' + index">{{ str }}</span>
+        <span
+          class="value"
+          v-for="(str, index) in '《用户协议》'"
+          :key="'b' + index">{{ str }}</span>
+        <span
+          class="label">与</span>
+        <span
+          class="value"
+          v-for="(str, index) in '《隐私协议》'"
+          :key="'c' + index">{{ str }}</span>
       </p>
     </div>
   </div>
@@ -33,9 +65,10 @@
 <script>
 import { Toast, Checkbox } from 'vant'
 import { sendSMS } from '../api/common'
-import { partnerLogin } from './api'
+import { login } from './api'
+import { isMobile, isSmscode } from '../utils/validate'
+import { clearLoginInfo } from '../utils'
 
-const STRCAPTURE = process.env.API_DOMAIN + '/api/captcha'
 export default {
   name: 'login',
   components: {
@@ -44,11 +77,9 @@ export default {
   data () {
     return {
       postData: {
-        partnerPhone: '',
-        capture: '',
+        phone: '',
         code: ''
       },
-      strCapture: STRCAPTURE,
       numCount: 60,
       timer: null,
       arrErrorList: [],
@@ -57,13 +88,12 @@ export default {
   },
   async mounted () {
     await this.$nextTick()
-    this.$refreshTitle('登录')
   },
   methods: {
     funLimitLength () {
-      const { partnerPhone, code } = this.postData
-      this.postData.partnerPhone = partnerPhone.length > 11 ? partnerPhone.slice(0, 11) : partnerPhone
-      this.postData.code = code.length > 4 ? code.slice(0, 4) : code
+      const { phone, code } = this.postData
+      this.postData.phone = phone.length > 11 ? phone.slice(0, 11) : phone
+      this.postData.code = code.length > 6 ? code.slice(0, 6) : code
     },
     funCutDown () {
       clearInterval(this.timer)
@@ -77,55 +107,49 @@ export default {
       }, 1000)
     },
     // 获取验证码
-    funGetCode () {
+    async funGetCode () {
       const numCount = this.numCount
-      const { partnerPhone, capture } = this.postData
+      const { phone } = this.postData
       if (numCount < 60 && numCount > 0) {
         return
       }
       this.numCount = 60
-      if (!(/^1[2|3|4|5|6|7|8|9]\d{9}$/.test(partnerPhone))) {
+      if (!isMobile(phone)) {
         Toast('请输入手机号码')
         return
       }
 
-      // if (!capture) {
-      //   Toast('请输入图片验证码')
-      //   return
-      // }
       this.funCutDown()
-      sendSMS(partnerPhone, 1, capture).then(res => {
-        if (res.status) {
+      try {
+        const { status, msg } = await sendSMS(phone)
+        if (status) {
           Toast('发送成功')
         } else {
-          Toast(res.msg)
-          this.funUpdateCapture()
+          Toast(msg)
           clearInterval(this.timer)
           this.numCount = 60
         }
-      }).catch(err => {
-        Toast(err.msg)
-        this.funUpdateCapture()
+      } catch (err) {
         clearInterval(this.timer)
         this.numCount = 60
-      })
-    },
-    funUpdateCapture () {
-      this.strCapture = STRCAPTURE + '?' + new Date().getTime()
+      }
     },
     verifyData () {
-      const { partnerPhone, code } = this.postData
+      const { phone, code } = this.postData
       this.arrErrorList = []
-      if (!/^1[2|3|4|5|6|7|8|9]\d{9}$/.test(partnerPhone)) {
+      if (!isMobile(phone)) {
         this.arrErrorList.push('请输入手机号码')
       }
-      if (!(/^\d{4}$/.test(code))) {
+      if (!isSmscode(code)) {
         this.arrErrorList.push('请输入验证码')
       }
+      if (!this.checked) {
+        this.arrErrorList.push('请勾选用户协议及隐私政策')
+      }
       return this.arrErrorList.length <= 0
     },
     funSubmit () {
-      const { partnerPhone, code } = this.postData
+      const { phone, code } = this.postData
       if (!this.verifyData()) {
         Toast({
           message: this.arrErrorList[0],
@@ -137,15 +161,25 @@ export default {
         duration: 1000 * 100,
         forbidClick: true
       })
-      partnerLogin(partnerPhone, code).then(res => {
+      login(phone, code).then(res => {
         myToast.clear()
         if (res.status) {
+          const { token } = res.data
+          clearLoginInfo()
+          this.$nextTick(() => {
+            this.$store.commit('common/UPDATE_PHONE', phone)
+            this.$store.commit('common/UPDATE_TOKEN', token)
+
+            this.$cookie.set('phone', phone, '30d')
+            this.$cookie.set('token', token, '30d')
+          })
+
           Toast({
             type: 'success',
-            message: '提交成功',
+            message: '登录成功',
             forbidClick: true,
             onClose: () => {
-              this.$router.replace({ path: '/partner' })
+              this.$router.go(-1)
             }
           })
           return
@@ -242,17 +276,6 @@ export default {
     }
   }
 
-  .capture-img {
-    @include vertical-center;
-    right: 14px;
-    z-index: 1;
-    display: block;
-    width: 125px;
-    height: 31px;
-    border-radius: 4px;
-    overflow: hidden;
-  }
-
   .get-code {
     @include vertical-center;
     right: 0;

+ 12 - 5
htmldev/dashboard/src/main.js

@@ -2,12 +2,12 @@ import Vue from 'vue'
 import App from './App.vue'
 import router from './router'
 import store from './store'
-import { toThousands } from './filter/toThousands'
+import cloneDeep from 'lodash/cloneDeep'
+import VueCookie from 'vue-cookie'
 import refreshTitle from './utils/refreshTitle'
 
-Vue.config.productionTip = false
-
-Vue.filter('toThousands', toThousands)
+// 全站配置
+window.SITE_CONFIG = {}
 Vue.prototype.$refreshTitle = refreshTitle
 Vue.directive('myBlur', {
   inserted: function (element) {
@@ -20,8 +20,15 @@ Vue.directive('myBlur', {
     }
   }
 })
+
+Vue.use(VueCookie)
+
 new Vue({
   router,
   store,
-  render: h => h(App)
+  render: h => h(App),
+  created () {
+    // 保存整站vuex本地储存初始状态
+    window.SITE_CONFIG.storeState = cloneDeep(store.state)
+  }
 }).$mount('#app')

+ 11 - 1
htmldev/dashboard/src/store/index.js

@@ -1,5 +1,6 @@
 import Vue from 'vue'
 import Vuex from 'vuex'
+import cloneDeep from 'lodash/cloneDeep'
 import common from './modules/common'
 
 Vue.use(Vuex)
@@ -7,5 +8,14 @@ Vue.use(Vuex)
 export default new Vuex.Store({
   modules: {
     common
-  }
+  },
+  mutations: {
+    // 重置vuex本地储存状态
+    resetStore (state) {
+      Object.keys(state).forEach((key) => {
+        state[key] = cloneDeep(window.SITE_CONFIG.storeState[key])
+      })
+    }
+  },
+  strict: process.env.NODE_ENV !== 'production'
 })

+ 12 - 5
htmldev/dashboard/src/store/modules/common.js

@@ -1,16 +1,23 @@
 const state = {
-  userInfo: {} // 用户信息
+  phone: '', // 登录手机号
+  token: '' // APP登录
 }
 
 const getters = {
-  userInfo (state) {
-    return state.userInfo
+  phone (state) {
+    return state.phone
+  },
+  token (state) {
+    return state.token
   }
 }
 
 const mutations = {
-  UPDATE_USERINFO (state, value) {
-    state.userInfo = value
+  UPDATE_PHONE (state, value) {
+    state.phone = value
+  },
+  UPDATE_TOKEN (state, value) {
+    state.token = value
   }
 }
 

+ 17 - 0
htmldev/dashboard/src/utils/index.js

@@ -0,0 +1,17 @@
+import Vue from 'vue'
+import store from '../store'
+
+/**
+ * 清除登录信息
+ */
+export function clearLoginInfo () {
+  Vue.cookie.delete('phone')
+  Vue.cookie.delete('token')
+
+  store.commit('common/UPDATE_PHONE', '')
+  store.commit('common/UPDATE_TOKEN', '')
+}
+
+export function clearStore () {
+  store.commit('resetStore')
+}

+ 1 - 1
htmldev/dashboard/src/utils/validate.js

@@ -19,7 +19,7 @@ export function isMobile (s) {
  * @param {*} s
  */
 export function isSmscode (s) {
-  return /^[0-9]{4}$/.test(s)
+  return /^[0-9]{6}$/.test(s)
 }
 
 /**

+ 8 - 0
htmldev/dashboard/vue.config.js

@@ -49,6 +49,14 @@ module.exports = {
         pathRewrite: {
           '^/Journalism': '/Journalism'
         }
+      },
+      '/api': {
+        target: 'http://tingbang-api.codedreamit.com',
+        ws: true,
+        changeOrigin: true,
+        pathRewrite: {
+          '^/api': '/api'
+        }
       }
     },
     overlay: {