ShareExercise.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <div v-show="showLogin" class="share-exercise">
  3. <div class="login">
  4. <div class="login-type">
  5. <div :class="['login-type-item', { active: 'TEACHER' === form.user_type }]" @click="form.user_type = 'TEACHER'">
  6. 教师
  7. </div>
  8. <div :class="['login-type-item', { active: 'STUDENT' === form.user_type }]" @click="form.user_type = 'STUDENT'">
  9. 学生
  10. </div>
  11. </div>
  12. <el-form ref="loginForm" :model="form" :rules="rules" label-position="right">
  13. <el-form-item prop="user_name">
  14. <el-input v-model="form.user_name" />
  15. </el-form-item>
  16. <el-form-item prop="password">
  17. <el-input v-model="form.password" type="password" show-password />
  18. </el-form-item>
  19. <el-form-item prop="verification_code_image_text" class="verification-code">
  20. <el-input v-model="form.verification_code_image_text" placeholder="验证码" @keyup.enter.native="signIn" />
  21. <el-image
  22. v-if="image_content_base64.length > 0"
  23. :src="`data:image/jpg;base64,${image_content_base64}`"
  24. @click="updateVerificationCode"
  25. />
  26. </el-form-item>
  27. <el-form-item>
  28. <el-button class="submit" type="primary" @click="signIn">登录</el-button>
  29. </el-form-item>
  30. </el-form>
  31. </div>
  32. <div class="tip">{{ tip }}</div>
  33. </div>
  34. </template>
  35. <script>
  36. import { GetShareRecordInfo, PageQueryExerciseList } from '@/api/exercise';
  37. import md5 from 'md5';
  38. import { GetVerificationCodeImage, GetLogo } from '@/api/app';
  39. import { setConfig } from '@/utils/auth';
  40. export default {
  41. name: 'ShareExercise',
  42. data() {
  43. const { query } = this.$route;
  44. const { share_record_id } = query;
  45. return {
  46. query,
  47. share_record_id,
  48. share_record: {
  49. access_popedom: -1,
  50. exercise_id: '',
  51. },
  52. showLogin: false,
  53. // 登录表单
  54. form: {
  55. user_type: 'STUDENT',
  56. user_name: '',
  57. password: '',
  58. is_password_md5: 'true',
  59. verification_code_image_id: '',
  60. verification_code_image_text: '',
  61. },
  62. rules: {
  63. user_name: [
  64. {
  65. required: true,
  66. message: '请输入用户名',
  67. trigger: 'blur',
  68. },
  69. ],
  70. password: [
  71. {
  72. required: true,
  73. message: '请输入密码',
  74. trigger: 'blur',
  75. },
  76. ],
  77. verification_code_image_text: [{ required: true, trigger: 'blur', message: '验证码不能为空' }],
  78. },
  79. image_content_base64: '',
  80. };
  81. },
  82. computed: {
  83. tip() {
  84. if (this.share_record.access_popedom === -1) return '正在加载...';
  85. return this.share_record.access_popedom === 1
  86. ? '分享链接为练习题答题链接,登录后可以开始答题'
  87. : '分享链接为练习题编辑链接,登录后可以开始编辑练习题';
  88. },
  89. },
  90. created() {
  91. let info = navigator.userAgent;
  92. // 通过正则表达式的test方法判断是否包含“Mobile”字符串
  93. let isPhone = /mobile|iPad/i.test(info);
  94. // 如果包含“Mobile”(是手机设备)则返回true
  95. if (isPhone) {
  96. window.location.href = `${window.location.origin}/GCLS-Mobile/#/open/share/exercise?share_record_id=${this.share_record_id}`;
  97. } else {
  98. this.getShareRecordInfo();
  99. }
  100. },
  101. methods: {
  102. getShareRecordInfo() {
  103. GetShareRecordInfo({
  104. share_record_id: this.share_record_id,
  105. })
  106. .then(({ share_record }) => {
  107. this.share_record = share_record;
  108. })
  109. .then(() => {
  110. PageQueryExerciseList({ page_capacity: 0, cur_page: 1, store_type: 0, search_content: '' })
  111. .then(() => {
  112. this.exerciseLink();
  113. })
  114. .catch(() => {
  115. this.updateVerificationCode();
  116. this.getLogo();
  117. this.showLogin = true;
  118. });
  119. })
  120. .catch(() => {});
  121. },
  122. exerciseLink() {
  123. // 1. 教师在没有权限的情况下,不能访问编辑练习题
  124. // 2. 学生不能访问编辑练习题
  125. if (
  126. (!this.$store.state.user.popedom_code_list.includes(2000007) &&
  127. this.form.user_type === 'TEACHER' &&
  128. this.share_record.access_popedom === 1) ||
  129. (this.form.user_type === 'STUDENT' && this.share_record.access_popedom === 1)
  130. ) {
  131. this.$message.error('您没有权限访问该页面');
  132. return;
  133. }
  134. if (this.share_record.access_popedom === 1) {
  135. this.$router.push({ path: '/exercise', query: { id: this.share_record.exercise_id } });
  136. }
  137. if (this.share_record.access_popedom === 2) {
  138. this.$router.push({
  139. path: '/answer',
  140. query: this.query,
  141. });
  142. }
  143. },
  144. updateVerificationCode() {
  145. GetVerificationCodeImage().then(({ image_id, image_content_base64: image }) => {
  146. this.form.verification_code_image_id = image_id;
  147. this.image_content_base64 = image;
  148. });
  149. },
  150. getLogo() {
  151. GetLogo().then((res) => {
  152. setConfig(res);
  153. });
  154. },
  155. signIn() {
  156. this.$refs.loginForm.validate((valid) => {
  157. if (!valid) return false;
  158. let _form = { ...this.form, password: md5(this.form.password).toUpperCase() };
  159. this.$store
  160. .dispatch('user/login', _form)
  161. .then(() => {
  162. this.exerciseLink();
  163. })
  164. .catch(() => {
  165. this.updateVerificationCode();
  166. });
  167. });
  168. },
  169. },
  170. };
  171. </script>
  172. <style lang="scss" scoped>
  173. .share-exercise {
  174. width: 100%;
  175. height: 100%;
  176. padding-top: 20%;
  177. background-color: $content-color;
  178. .login {
  179. width: 50vw;
  180. max-width: 1200px;
  181. padding: 24px;
  182. margin: auto;
  183. background-color: #f0f0f0;
  184. border: $border;
  185. border-radius: 4px;
  186. &-type {
  187. display: flex;
  188. align-items: center;
  189. justify-content: center;
  190. width: 400px;
  191. padding: 2px;
  192. margin: 0 auto;
  193. margin-bottom: 12px;
  194. background-color: #fafafa;
  195. border-radius: 4px;
  196. &-item {
  197. width: 200px;
  198. height: 36px;
  199. line-height: 36px;
  200. color: $text-color;
  201. text-align: center;
  202. cursor: pointer;
  203. &.active {
  204. color: $main-color;
  205. background-color: $fill-color;
  206. border-radius: 4px;
  207. box-shadow: 0 2px 8px rgba(0, 0, 0, 10%);
  208. }
  209. }
  210. }
  211. :deep(.el-form) {
  212. max-width: 400px;
  213. margin: 0 auto;
  214. .verification-code {
  215. .el-input {
  216. width: calc(100% - 90px);
  217. margin-right: 10px;
  218. &__inner {
  219. background-color: #fff;
  220. }
  221. }
  222. .el-image {
  223. height: 30px;
  224. vertical-align: bottom;
  225. cursor: pointer;
  226. }
  227. }
  228. .submit {
  229. width: 100%;
  230. }
  231. }
  232. }
  233. .tip {
  234. width: 100%;
  235. padding: 8px 0;
  236. margin-top: 40px;
  237. text-align: center;
  238. background-color: #fff;
  239. border-top: $border;
  240. border-bottom: $border;
  241. }
  242. }
  243. </style>