lrf402788946 преди 5 години
родител
ревизия
eca9d9132f
променени са 4 файла, в които са добавени 25 реда и са изтрити 1 реда
  1. BIN
      assets/wechat.png
  2. 2 1
      components/qrcode.vue
  3. 18 0
      layout/admin/navBar.vue
  4. 5 0
      store/login.js

BIN
assets/wechat.png


+ 2 - 1
components/qrcode.vue

@@ -11,6 +11,7 @@ export default {
   name: 'qrcode',
   props: {
     qrcode: null,
+    uri: { type: String },
   },
   components: {},
   data: () => ({
@@ -27,7 +28,7 @@ export default {
       // 创建二维码
       if (!this.qrcode) return;
       //二维码地址应该是变量,不过这里需要处理
-      let uri = `${Vue.config.weixin.baseUrl}/qrcode/${this.qrcode}/scan`;
+      let uri = `${Vue.config.weixin.baseUrl}${this.uri}`;
       if (uri.startsWith('/')) {
         uri = `${location.protocol}//${location.host}${uri}`;
       }

+ 18 - 0
layout/admin/navBar.vue

@@ -19,6 +19,7 @@
               <span class="user-name" v-else @click="toLogin">请登录</span>
             </div>
             <el-dropdown-menu class="user-dropdown" slot="dropdown" v-if="user && user.userid">
+              <el-dropdown-item :divided="true" command="weixin"> <img :src="weixin" style="zoom:0.1" /> 绑定/更绑微信 </el-dropdown-item>
               <el-dropdown-item :divided="true" icon="el-icon-key" command="passwd">
                 修改密码
               </el-dropdown-item>
@@ -33,10 +34,18 @@
     <el-dialog title="修改密码" :visible.sync="dialog" center @close="toClose" :destroy-on-close="true">
       <data-form :data="info" :fields="fields" :rules="rules" @save="handleSave" :isNew="true"> </data-form>
     </el-dialog>
+    <el-dialog :visible.sync="wxDialog" title="绑定微信" width="30%" center :destroy-on-close="true">
+      <el-row type="flex" justify="center">
+        <el-col :span="24" style="text-align:center">
+          <img :src="dataUrl" />
+        </el-col>
+      </el-row>
+    </el-dialog>
   </div>
 </template>
 
 <script>
+import QRCode from 'qrcode';
 import dataForm from '@frame/components/form';
 import { mapState, mapMutations, createNamespacedHelpers } from 'vuex';
 import _ from 'lodash';
@@ -46,8 +55,11 @@ export default {
   props: {},
   components: { dataForm },
   data: () => ({
+    weixin: require('@frame/assets/wechat.png'),
+    dataUrl: '',
     info: {},
     dialog: false,
+    wxDialog: false,
     fields: [{ label: '密码', required: true, model: 'passwd', type: 'password', tip: '密码至少6位' }],
     rules: {
       passwd: [
@@ -74,6 +86,7 @@ export default {
     handleCommand(type) {
       if (type === 'logout') this.toLogout();
       if (type === 'passwd') this.toPasswd();
+      if (type === 'weixin') this.bind();
     },
     async toLogin() {
       this.$router.push({ name: 'login' });
@@ -90,6 +103,11 @@ export default {
       let res = await this.update(data);
       if (this.$checkRes(res, '修改成功', '修改失败')) this.toClose();
     },
+    async bind() {
+      let uri = `http://free.liaoningdoupo.com/api/train/authtest?redirect_uri=http://10.16.10.7:8001/confirm&uid=${this.user.id}&type=1`;
+      this.dataUrl = await QRCode.toDataURL(uri);
+      this.wxDialog = true;
+    },
   },
 };
 </script>

+ 5 - 0
store/login.js

@@ -8,6 +8,7 @@ const api = {
   interface: `/api/train/login`,
   user: id => `/api/train/user/update/${id}`,
   bind: `/api/train/user/bind`,
+  userBind: `/api/train/user/userbind`,
 };
 const state = () => ({});
 const mutations = {};
@@ -63,6 +64,10 @@ const actions = {
     let res = await this.$axios.$post(`${api.bind}`, payload);
     return res;
   },
+  async userBind({ commit }, payload) {
+    let res = await this.$axios.$post(`${api.userBind}`, payload);
+    return res;
+  },
 };
 export default {
   namespaced: true,