Explorar el Código

完成扫码加入名单的功能

liqk hace 4 años
padre
commit
d57b61331e

+ 4 - 0
TEAMModelOS/ClientApp/src/api/service.js

@@ -16,4 +16,8 @@ export default {
     sandMailCode: function (host,data) {
         return post(`${host}/service/sandmail/pin`, data)
     },
+    /* 裝置或服務取得金鑰及刷新金鑰 */
+    getToken: function (host,data) {
+        return post(`${host}/oauth2/token`, data)
+    },
 }

+ 2 - 1
TEAMModelOS/ClientApp/src/locale/lang/en-US/cusMgt.js

@@ -248,6 +248,7 @@ export default {
         errorContent:'课程名单获取失败,请重新扫码加入!',
         joinOk:'加入成功',
         joinErr:'加入失敗',
-        getListErr:'獲取名單信息失敗'
+        getListErr:'獲取名單信息失敗',
+        hasJoin:'恭喜您,已經加入成功! '
     }
 }

+ 2 - 1
TEAMModelOS/ClientApp/src/locale/lang/zh-CN/cusMgt.js

@@ -248,6 +248,7 @@ export default {
         errorContent:'课程名单获取失败,请重新扫码加入!',
         joinOk:'加入成功',
         joinErr:'加入失败',
-        getListErr:'获取名单信息失败'
+        getListErr:'获取名单信息失败',
+        hasJoin:'恭喜您,已经加入成功!'
     }
 }

+ 2 - 1
TEAMModelOS/ClientApp/src/locale/lang/zh-TW/cusMgt.js

@@ -248,6 +248,7 @@ export default {
         errorContent:'課程名單獲取失敗,請重新掃碼加入! ',
         joinOk:'加入成功',
         joinErr:'加入失敗',
-        getListErr:'獲取名單信息失敗'
+        getListErr:'獲取名單信息失敗',
+        hasJoin:'恭喜您,已經加入成功! '
     }  
 }

+ 58 - 7
TEAMModelOS/ClientApp/src/view/joinclass/JoinClass.vue

@@ -1,6 +1,6 @@
 <template>
     <div class="join-wrap">
-        <div class="join-main-box">
+        <div class="join-main-box" v-show="!isJoin">
             <p class="join-title">
                 <span>
                     {{$t('cusMgt.join.title')}}
@@ -30,24 +30,36 @@
                 {{$t('cusMgt.join.joinBtn')}}
             </div>
         </div>
+        <div v-show="isJoin" class="join-main-box">
+            <p class="join-title">
+                <span>
+                    {{$t('cusMgt.join.title')}}
+                </span>
+            </p>
+            <Icon type="md-checkmark-circle-outline" color="#19be6b" size="120"/>
+            <p class="success-tips">{{$t('cusMgt.join.hasJoin')}}</p>
+        </div>
     </div>
 </template>
 <script>
+import jwtDecode from 'jwt-decode'
 export default {
     data() {
         return {
+            isJoin: false,
             tId: '',
             tName: '',
             listId: '',
             listName: '',
             cusName: '',
-            tmid: ''
+            code: '',
+            userId: ''
         }
     },
     methods: {
         joinList(stulist) {
             if (stulist) {
-                stulist.tmids.push(this.tmid)
+                stulist.tmids.push(this.userId)
                 this.$api.courseMgmt.upsertStulist({
                     scope: 'private',
                     stuList: stulist
@@ -55,6 +67,7 @@ export default {
                     res => {
                         if (!res.error) {
                             this.$Message.success(this.$t('cusMgt.join.joinOk'))
+                            this.isJoin = true
                         } else {
                             this.$Message.error(this.$t('cusMgt.join.joinErr'))
                         }
@@ -76,9 +89,12 @@ export default {
             }
             this.$api.courseMgmt.findListSummary(params).then(
                 res => {
-                    if (!res.error && res.stulist && res.stulist.length) {
-                        console.log(res)
-                        this.joinList(res.stulist[0])
+                    if (!res.error && res.stuList && res.stuList.length) {
+                        if (res.stuList[0].tmids.includes(this.userId)) {
+                            this.isJoin = true
+                        } else {
+                            this.joinList(res.stuList[0])
+                        }
                     } else {
                         this.$Message.error(this.$t('cusMgt.join.getListErr'))
                     }
@@ -95,16 +111,50 @@ export default {
         this.listId = this.$route.query.listId   //名单id
         this.listName = this.$route.query.listName //名单
         this.cusName = this.$route.query.cusName  //课程名称
-        if (!this.listId || !this.tId) {
+        this.code = this.$route.query.code  //登录成功返回的code
+        if (!this.listId || !this.tId || !this.code) {
             this.$Modal.error({
                 title: this.$t('cusMgt.join.errorTile'),
                 content: this.$t('cusMgt.join.errorContent')
             })
+        } else {
+            //获取登录信息
+            let srvAdr = this.$store.state.config.srvAdr
+            let host = srvAdr == 'Global' ? this.$store.state.config.Global.coreAPIUrl : this.$store.state.config.China.coreAPIUrl
+            let clientId = srvAdr == 'Global' ? this.$store.state.config.Gloabl.clientID : this.$store.state.config.China.clientID
+            this.$api.service.getToken(host, {
+                grant_type: "authorization_code",
+                client_id: clientId,
+                code: this.code
+            }).then(
+                res => {
+                    if (!res.error) {
+                        let tokenData = jwtDecode(res.id_token)
+                        if (tokenData) {
+                            this.userId = tokenData.sub
+                            console.log(this.userId)
+                        } else {
+                            this.$Message.error('登录信息解析失败')
+                        }
+                    } else {
+                        this.$Message.error('用户信息获取失败')
+                    }
+                },
+                err => {
+                    this.$Message.error('用户信息获取失败')
+                }
+            )
+
         }
     }
 }
 </script>
 <style scoped lang="less">
+.success-tips{
+    color: white;
+    font-size: 16px;
+    margin-top: 20px;
+}
 .join-wrap {
     display: flex;
     flex-direction: column;
@@ -115,6 +165,7 @@ export default {
     background-image: url("../../assets/image/bak_light.jpg");
 }
 .join-btn {
+    cursor: pointer;
     width: 100%;
     margin: auto;
     margin-top: 60px;