Browse Source

上测试

喻文俊 3 years ago
parent
commit
88b261b336

+ 4 - 0
.env.development

@@ -1,6 +1,10 @@
 # 文件标记
 EVN = 'development'
 
+# 网站地址
+# LOCALHOSE = 'https://zp-b.caimei365.com'
+LOCALHOSE = 'http://192.168.2.81:3000'
+
 # 接口api地址
 # BASE_URL = 'https://zplma-b.caimei365.com'
 BASE_URL = 'http://192.168.2.68:8012'

+ 4 - 4
components/LdmLogin/index.vue

@@ -44,7 +44,7 @@ export default {
       show: false,
       sendStatus: 0,
       formData: {
-        appId: '',
+        authUserId: '',
         mobile: '',
         verifyCode: '',
       },
@@ -52,7 +52,7 @@ export default {
     }
   },
   computed: {
-    ...mapGetters(['loginVisiable', 'appId']),
+    ...mapGetters(['loginVisiable', 'appId', 'authUserId']),
     sendCodeBtnText() {
       return this.sendStatus === 0
         ? '发送验证码'
@@ -67,7 +67,7 @@ export default {
   methods: {
     async onSubmit() {
       try {
-        this.formData.appId = this.appId
+        this.formData.authUserId = this.authUserId
         const res = await this.$http.api.customLogin(this.formData)
         this.$store.dispatch('user/login', res.data)
         this.$store.commit('app/HIDE_LOGIN')
@@ -89,7 +89,7 @@ export default {
         // 发送验证码
         const res = await this.$http.api.sendVerifyCode({
           mobile: this.formData.mobile,
-          appId: this.appId,
+          authuserId: this.authuserId,
           type: 1,
         })
         this.$toast('验证码已发送')

+ 5 - 5
components/SimpleLogin/index.vue

@@ -5,7 +5,7 @@
         <div class="block flex items-center flex-col py-6">
           <div class="close" @click="onClose"></div>
           <div class="title pb-6">登录</div>
-          <div class="forlogoutm">
+          <div class="form">
             <div class="form-item mb-4">
               <input
                 type="text"
@@ -40,7 +40,7 @@ export default {
       show: false,
       sendStatus: 0,
       formData: {
-        appId: '',
+        authUserId: '',
         mobile: '',
         verifyCode: '',
       },
@@ -48,7 +48,7 @@ export default {
     }
   },
   computed: {
-    ...mapGetters(['loginVisiable', 'appId']),
+    ...mapGetters(['loginVisiable', 'authUserId']),
     sendCodeBtnText() {
       return this.sendStatus === 0
         ? '发送验证码'
@@ -63,7 +63,7 @@ export default {
   methods: {
     async onSubmit() {
       try {
-        this.formData.appId = this.appId
+        this.formData.authUserId = this.authUserId
         const res = await this.$http.api.customLogin(this.formData)
         this.$store.dispatch('user/login', res.data)
         this.$store.commit('app/HIDE_LOGIN')
@@ -85,7 +85,7 @@ export default {
         // 发送验证码
         const res = await this.$http.api.sendVerifyCode({
           mobile: this.formData.mobile,
-          appId: this.appId,
+          authUserId: this.authUserId,
           type: 1,
         })
         this.$toast('验证码已发送')

+ 49 - 0
generate.js

@@ -0,0 +1,49 @@
+const fs = require('fs')
+const path = require('path')
+
+// 将文件路径截取为路由路径
+function slicePathToRoute(filePath) {
+  return filePath
+    .slice(0, filePath.length - 4)
+    .replace(path.join(__dirname, 'pages'), '')
+}
+
+function generateDirToRoutes(filename) {
+  const routes = []
+  // 读取文件夹
+  function readDir(last, next) {
+    const entry = path.join(last, next)
+    const stat = fs.statSync(entry)
+    // 如果是文件夹
+    if (stat.isDirectory()) {
+      const dirList = fs.readdirSync(entry)
+      dirList.forEach((dir) => {
+        readDir(entry, dir)
+      })
+    } else {
+      // 文件 直接打印
+      routes.push(slicePathToRoute(entry))
+    }
+  }
+  readDir(__dirname, filename)
+  return routes
+}
+
+function generateRoutes(list, name, root = 'pages') {
+  const reslut = []
+  const routes = generateDirToRoutes(path.join(root, name))
+  console.log(routes)
+  list.forEach((item) => {
+    routes.forEach((route) => {
+      const res = route.replace(`\\${name}\\`, '')
+      if (res.startsWith(item.type)) {
+        reslut.push(route.replace(name, item.id))
+      }
+    })
+  })
+  return reslut
+}
+
+const list = [{ id: 102, type: 'ldm' }]
+const routes = generateRoutes(list, '_template')
+console.log(routes)

+ 0 - 10
keys.config.js

@@ -1,10 +0,0 @@
-export default {
-  ph: {
-    appId: 'wx6512b1dfb84c28e1',
-    authUserId: '',
-  },
-  ldm: {
-    appId: 'wx6512b1dfb84c28e1',
-    authUserId: '',
-  },
-}

+ 6 - 1
layouts/app-ldm.vue

@@ -11,12 +11,17 @@
 
 <script>
 import { getCookies } from '@/utils/auth'
-import keys from '@/keys.config'
 import { mapGetters } from 'vuex'
 export default {
   computed: {
     ...mapGetters(['userInfo', 'type', 'accessToken', 'authUserId']),
   },
+  head() {
+    return {
+      title: '德国WELLCOMET LDM® 官方查询系统',
+      link: [{ rel: 'icon', type: 'image/x-icon', href: '/ldm.ico' }],
+    }
+  },
   data() {
     return {
       isMounted: false,

+ 18 - 2
layouts/app.vue

@@ -16,7 +16,7 @@
           <template v-else>
             <div
               class="login pr-3 pl-3 border rounded-sm border-white leading-6"
-              @click="$store.commit('app/SHOW_LOGIN')"
+              @click="onLogin"
             >
               登录
             </div>
@@ -37,9 +37,16 @@
 <script>
 import { getCookies } from '@/utils/auth'
 import { mapGetters } from 'vuex'
+import { isWeChat } from '~/utils/validator'
+import { toAuthorization } from '~/utils'
 export default {
   computed: {
-    ...mapGetters(['userInfo', 'type', 'accessToken', 'authUserId']),
+    ...mapGetters(['userInfo', 'type', 'accessToken', 'authUserId', 'appId']),
+  },
+  head() {
+    return {
+      link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
+    }
   },
   data() {
     return {
@@ -89,6 +96,15 @@ export default {
       }
     },
 
+    onLogin() {
+      // 在微信浏览器中使用微信授权登录
+      if (isWeChat() && this.appId) {
+        const payload = { authUserId: this.authUserId, type: this.type }
+        return toAuthorization(this.appId, payload)
+      }
+      this.$store.commit('app/SHOW_LOGIN')
+    },
+
     // 退出登录
     logout() {
       this.$store.dispatch('user/logout')

+ 9 - 1
nuxt.config.js

@@ -1,9 +1,17 @@
+// import generateRoutes from './generate'
+// const list = [{ id: 102, type: 'app' }]
+// const routes = generateRoutes(list, '_template')
+
 // 运行环境
 const envConfig = require('dotenv').config({
   path: `.env${process.env.ENV ? `.${process.env.ENV}` : ''}`,
 })
 
 export default {
+  // generate: {
+  //   routes: routes,
+  // },
+
   // Global page headers: https://go.nuxtjs.dev/config-head
   head: {
     title: '认证通',
@@ -16,7 +24,7 @@ export default {
       { name: 'description', content: '认证通|一款专业的正品认证SaaS软件系统' },
       { name: 'format-detection', content: 'telephone=no' },
     ],
-    link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
+    // link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
   },
 
   // Global CSS: https://go.nuxtjs.dev/config-css

+ 1 - 1
pages/_old/_.vue

@@ -8,7 +8,7 @@ import { getQueryObject } from '@/utils/index'
 export default {
   data() {
     return {
-      appId: '',
+      authUserId: '',
       redirectInfo: null,
     }
   },

+ 3 - 3
pages/_template/app/approve/club/index.vue

@@ -79,7 +79,7 @@ export default {
       isRequest: true,
       list: [],
       listQuery: {
-        appId: '',
+        authUserId: '',
         lngAndLat: '',
         clubName: '',
         provinceId: '',
@@ -93,7 +93,7 @@ export default {
     }
   },
   computed: {
-    ...mapGetters(['supplierInfo', 'appId', 'authUserId']),
+    ...mapGetters(['supplierInfo', 'authUserId', 'authUserId']),
     emptyList() {
       return 3 - (this.list.length % 3)
     },
@@ -134,7 +134,7 @@ export default {
         this.$toast('获取定位信息失败,请确保您开启的定位权限并保存网络畅通')
         this.isRequest = false
       }
-      this.listQuery.appId = this.appId
+      this.listQuery.authUserId = this.authUserId
       // 获取机构列表
       this.fetchList()
     },

+ 14 - 6
pages/_template/app/approve/device/index.vue

@@ -18,15 +18,15 @@
       </div>
       <!-- 列表 -->
       <div class="list">
-        <nuxt-link
+        <div
           class="section flex items-center mb-4"
           v-for="item in list"
           :key="item.productTypeId"
-          :to="`/${authUserId}/app/approve/device/${item.productTypeId}`"
+          @click="toDetail(item)"
         >
           <img class="cover" :src="item.image" />
           <div class="name" v-text="item.name"></div>
-        </nuxt-link>
+        </div>
         <div class="empty" v-for="i in emptyList" :key="'empty-' + i"></div>
       </div>
 
@@ -55,7 +55,7 @@ export default {
     return {
       isRequest: true,
       listQuery: {
-        appId: '',
+        authUserId: '',
         productName: '',
         pageNum: 1,
         pageSize: 10,
@@ -65,7 +65,7 @@ export default {
     }
   },
   computed: {
-    ...mapGetters(['supplierInfo', 'appId', 'authUserId']),
+    ...mapGetters(['supplierInfo', 'authUserId', 'authUserId']),
     emptyList() {
       return 3 - (this.list.length % 3)
     },
@@ -77,7 +77,7 @@ export default {
     // 获取设备分类
     async fetchList() {
       try {
-        this.listQuery.appId = this.appId
+        this.listQuery.authUserId = this.authUserId
         const res = await this.$http.api.getAuthProductCateList(this.listQuery)
         this.list = res.data.list
         this.total = res.data.total
@@ -87,6 +87,14 @@ export default {
         this.isRequest = false
       }
     },
+    // 设备详情
+    toDetail(item) {
+      localStorage.setItem(
+        'deviceInfo',
+        JSON.stringify({ productTypeId: item.productTypeId })
+      )
+      this.$router.push(`/${this.authUserId}/app/approve/device/list`)
+    },
     // 搜索
     onSearch() {
       this.listQuery.pageNum = 1

+ 9 - 2
pages/_template/app/approve/device/_id.vue → pages/_template/app/approve/device/list.vue

@@ -78,12 +78,19 @@ export default {
     },
   },
   mounted() {
-    this.fetchList()
+    this.initData()
   },
   methods: {
+    initData() {
+      let deviceInfo = localStorage.getItem('deviceInfo')
+      if (deviceInfo) {
+        deviceInfo = JSON.parse(deviceInfo)
+        this.listQuery.productTypeId = deviceInfo.productTypeId
+        this.fetchList()
+      }
+    },
     async fetchList() {
       try {
-        this.listQuery.productTypeId = this.$route.params.id
         const res = await this.$http.api.getAuthProductList(this.listQuery)
         this.list = res.data.list
         this.total = res.data.total

+ 3 - 3
pages/_template/app/approve/personnel/operate/index.vue

@@ -60,7 +60,7 @@ export default {
     return {
       isRequest: false,
       listQuery: {
-        appId: '',
+        authUserId: '',
         doctorType: 1,
         doctorName: '',
         pageNum: 1,
@@ -71,7 +71,7 @@ export default {
     }
   },
   computed: {
-    ...mapGetters(['supplierInfo', 'appId', 'authUserId']),
+    ...mapGetters(['supplierInfo', 'authUserId', 'authUserId']),
     isEmpty() {
       return this.list.length === 0
     },
@@ -85,7 +85,7 @@ export default {
   methods: {
     async fetchList() {
       try {
-        this.listQuery.appId = this.appId
+        this.listQuery.authUserId = this.authUserId
         const res = await this.$http.api.fetchDoctorList(this.listQuery)
         this.list = res.data.list
         this.total = res.data.total

+ 8 - 1
pages/_template/app/index.vue

@@ -31,6 +31,8 @@
 
 <script>
 import { mapGetters } from 'vuex'
+import { toAuthorization } from '~/utils'
+import { isWeChat } from '~/utils/validator'
 export default {
   layout: 'app',
   data() {
@@ -69,13 +71,18 @@ export default {
     }
   },
   computed: {
-    ...mapGetters(['supplierInfo', 'authUserId']),
+    ...mapGetters(['supplierInfo', 'authUserId', 'appId', 'type']),
   },
   created() {},
   methods: {
     toDetail(item) {
       const hasLogin = this.$store.getters.accessToken
       if (item.id > 0 && !hasLogin) {
+        // 在微信浏览器中使用微信授权登录
+        if (isWeChat() && this.appId) {
+          const payload = { authUserId: this.authUserId, type: this.type }
+          return toAuthorization(this.appId, payload)
+        }
         this.$toast({ message: '请先登录', duration: 1000 })
         this.$store.commit('app/SHOW_LOGIN')
         return

+ 3 - 3
pages/_template/ldm/approve/club/index.vue

@@ -74,7 +74,7 @@ export default {
       isRequest: true,
       list: [],
       listQuery: {
-        appId: '',
+        authUserId: '',
         lngAndLat: '',
         clubName: '',
         provinceId: '',
@@ -88,7 +88,7 @@ export default {
     }
   },
   computed: {
-    ...mapGetters(['supplierInfo', 'appId']),
+    ...mapGetters(['supplierInfo', 'authUserId']),
     emptyList() {
       return 3 - (this.list.length % 3)
     },
@@ -129,7 +129,7 @@ export default {
         this.$toast('获取定位信息失败,请确保您开启的定位权限并保存网络畅通')
         this.isRequest = false
       }
-      this.listQuery.appId = this.appId
+      this.listQuery.authUserId = this.authUserId
       // 获取机构列表
       this.fetchList()
     },

+ 3 - 3
pages/_template/ldm/approve/personnel/training/index.vue

@@ -41,7 +41,7 @@ export default {
     return {
       isRequest: false,
       listQuery: {
-        appId: '',
+        authUserId: '',
         doctorType: 2,
         doctorName: '',
         pageNum: 1,
@@ -52,7 +52,7 @@ export default {
     }
   },
   computed: {
-    ...mapGetters(['supplierInfo', 'appId']),
+    ...mapGetters(['supplierInfo', 'authUserId']),
   },
   mounted() {
     this.fetchList()
@@ -60,7 +60,7 @@ export default {
   methods: {
     async fetchList() {
       try {
-        this.listQuery.appId = this.appId
+        this.listQuery.authUserId = this.authUserId
         const res = await this.$http.api.fetchDoctorList(this.listQuery)
         this.list = res.data.list
         this.total = res.data.total

+ 8 - 0
pages/_template/ldm/index.vue

@@ -27,6 +27,8 @@
 </template>
 
 <script>
+import { toAuthorization } from '~/utils'
+import { isWeChat } from '~/utils/validator'
 export default {
   layout: 'app-ldm',
   data() {
@@ -57,6 +59,12 @@ export default {
     toDetail(item) {
       const hasLogin = this.$store.getters.accessToken
       if (item.id > 0 && !hasLogin) {
+        const appId = this.$store.getters.appId
+        // 在微信浏览器中使用微信授权登录
+        if (isWeChat() && appId) {
+          const payload = { authUserId: this.authUserId, type: this.type }
+          return toAuthorization(appId, payload)
+        }
         this.$toast({ message: '请先登录', duration: 1000 })
         this.$store.commit('app/SHOW_LOGIN')
         return

+ 171 - 0
pages/auth/index.vue

@@ -0,0 +1,171 @@
+<template>
+  <div class="auth-page" v-if="showBind">
+    <div class="form p-4">
+      <div class="form-item mb-4">
+        <input type="text" placeholder="手机号" v-model="formData.mobile" />
+      </div>
+      <div class="form-item mb-4 code">
+        <input
+          type="text"
+          placeholder="验证码"
+          class="code"
+          v-model="formData.verifyCode"
+        />
+        <span class="send" @click="onSend">{{ sendCodeBtnText }}</span>
+      </div>
+      <div class="submit" @click="onSubmit">登录</div>
+    </div>
+  </div>
+</template>
+
+<script>
+import { isMobile } from '@/utils/validator'
+export default {
+  data() {
+    return {
+      showBind: false,
+      sendStatus: 0,
+      formData: {
+        authUserId: '',
+        appId: '',
+        openId: '',
+        accessToken: '',
+        mobile: '',
+        verifyCode: '',
+      },
+      path: '',
+      code: '',
+    }
+  },
+  computed: {
+    sendCodeBtnText() {
+      return this.sendStatus === 0
+        ? '发送验证码'
+        : `再次发送${this.sendStatus}s`
+    },
+  },
+  mounted() {
+    this.initData()
+  },
+  methods: {
+    // 初始化数据
+    initData() {
+      // 获取链接参数
+      const { code, type, id, appId } = this.$route.query
+      this.code = code
+      this.formData.appId = appId
+      this.formData.authUserId = parseInt(id)
+      this.path = `/${id}/${type}`
+      // 尝试微信授权自动登录
+      this.autoLogin()
+    },
+
+    // 绑定并登录
+    async onSubmit() {
+      try {
+        const res = await this.$http.api.customLogin(this.formData)
+        this.$store.dispatch('user/login', res.data)
+        this.$toast('登录成功')
+        setTimeout(() => {
+          this.$router.push(this.path)
+        }, 1000)
+      } catch (error) {
+        console.log(error)
+      }
+    },
+
+    // 发送验证码
+    async onSend() {
+      if (this.sendStatus > 0) return
+      // 验证手机号是否合法
+      if (!isMobile(this.formData.mobile)) {
+        this.$toast('请输入正确的手机号')
+        return
+      }
+      try {
+        // 发送验证码
+        const res = await this.$http.api.sendVerifyCode({
+          mobile: this.formData.mobile,
+          authUserId: this.formData.authUserId,
+          type: 1,
+        })
+        this.$toast('验证码已发送')
+        // 开启倒计时
+        this.countdown()
+      } catch (error) {
+        console.log(error)
+      }
+    },
+
+    // 短信倒计时
+    countdown() {
+      this.sendStatus = 30
+      this.timer = setInterval(() => {
+        if (this.sendStatus === 0) {
+          clearInterval(this.timer)
+          return
+        }
+        this.sendStatus--
+      }, 1000)
+    },
+
+    // 微信授权登录
+    async autoLogin() {
+      try {
+        const res = await this.$http.api.wechatLogin({
+          code: this.code,
+          appId: this.formData.appId,
+        })
+        this.$store.dispatch('user/login', res.data)
+        this.$router.push(this.path)
+      } catch (error) {
+        // 未绑定微信号
+        if (error.code === -2) {
+          this.$toast('未绑定手机号')
+          this.showBind = true
+          this.formData.openId = error.data.openId
+          this.formData.accessToken = error.data.accessToken
+        } else {
+          // 其他错误跳转首页
+          setTimeout(() => {
+            this.$router.push(this.path)
+          }, 1000)
+        }
+      }
+    },
+  },
+}
+</script>
+
+<style scoped lang="scss">
+.auth-page {
+  .form {
+    .form-item {
+      position: relative;
+      border-bottom: 0.1vw solid #d8d8d8;
+      input {
+        display: block;
+        width: 100%;
+        font-size: 4.2vw;
+        line-height: 10vw;
+      }
+
+      .send {
+        position: absolute;
+        right: 2.4vw;
+        top: 50%;
+        transform: translateY(-50%);
+        font-size: 3.4vw;
+      }
+    }
+
+    .submit {
+      background: #bc1724;
+      font-size: 3.2vw;
+      color: #fff;
+      text-align: center;
+      line-height: 10vw;
+    }
+  }
+}
+</style>

+ 0 - 11
pages/entry/approve.vue

@@ -1,11 +0,0 @@
-<template>
-  <div></div>
-</template>
-
-<script>
-export default {
-  asyncData({ redirect }) {
-    redirect('/app/approve')
-  },
-}
-</script>

+ 0 - 11
pages/entry/doc.vue

@@ -1,11 +0,0 @@
-<template>
-  <div></div>
-</template>
-
-<script>
-export default {
-  asyncData({ redirect }) {
-    redirect('/app/database/article')
-  },
-}
-</script>

+ 0 - 11
pages/entry/feedback.vue

@@ -1,11 +0,0 @@
-<template>
-  <div></div>
-</template>
-
-<script>
-export default {
-  asyncData({ redirect }) {
-    redirect('/app/feedback')
-  },
-}
-</script>

BIN
static/ldm.ico


+ 5 - 4
utils/index.js

@@ -29,10 +29,11 @@ export function drawLogo(text = '', len = 4) {
 }
 
 // 跳转到授权页面
-export function toAuthorization(appId) {
-  window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${encodeURIComponent(
-    process.env.VUE_APP_LOCAL + '/#/code'
-  )}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
+export function toAuthorization(appId, payload) {
+  const type = payload.type.split('/')[1]
+  const url = `${process.env.LOCALHOSE}/auth?id=${payload.authUserId}&type=${type}&appId=${appId}`
+  const redirect_uri = encodeURIComponent(url)
+  window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
 }
 
 /** 时间格式化

+ 12 - 0
utils/old-routes.js

@@ -4,6 +4,18 @@
  */
 
 const oldRoutes = [
+  {
+    path: '/entry/approve',
+    redirect: '/app/approve',
+  },
+  {
+    path: '/entry/doc',
+    redirect: '/app/database/article',
+  },
+  {
+    path: '/entry/feedback',
+    redirect: '/app/feedback',
+  },
   {
     path: '/home',
     redirect: '/app',