index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <view>
  3. <navbar :back="false" />
  4. <!-- 登录 -->
  5. <view class="login">
  6. <view class="title-big">欢迎登录</view>
  7. <view class="title">国际中文智慧教育引擎</view>
  8. <uni-forms ref="form" :model="formData" :rules="rules">
  9. <uni-forms-item name="user_type">
  10. <uni-data-select class="login-text" v-model="value" :localdata="userTypeList" @change="change"
  11. placeholder="请选择登录身份" />
  12. </uni-forms-item>
  13. <uni-forms-item name="user_name">
  14. <uni-easyinput class="login-text" type="text" v-model="formData.user_name" placeholder="输入邮箱、手机号或用户名"
  15. :styles="login_text_styles" :placeholderStyle="placeholderStyle" />
  16. </uni-forms-item>
  17. <uni-forms-item name="password">
  18. <uni-easyinput class="login-text" type="password" v-model="formData.password" placeholder="输入登录密码"
  19. :styles="login_text_styles" :placeholderStyle="placeholderStyle" />
  20. </uni-forms-item>
  21. <uni-forms-item name="verification_code_image_text" class="verification-code">
  22. <uni-easyinput class="login-text" type="text" v-model="formData.verification_code_image_text"
  23. placeholder="输入验证码" :styles="login_text_styles" :placeholderStyle="placeholderStyle" />
  24. </uni-forms-item>
  25. <image v-if="image_content_base64.length > 0" :src="`data:image/jpg;base64,${image_content_base64}`"
  26. @click="updateVerificationCode" mode="widthFix">
  27. </image>
  28. </uni-forms>
  29. <view class="forget">
  30. <text @click="forget">忘记密码?</text>
  31. </view>
  32. <button class="submit" @click="submitForm">登 录</button>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import md5 from 'md5';
  38. import {
  39. GetVerificationCodeImage,
  40. GetLogo,
  41. ParseAccessToken
  42. } from '@/api/api';
  43. import {
  44. loginControlIsEffectiveUser
  45. } from '@/api/user.js';
  46. import {
  47. getToken,
  48. setConfig,
  49. getConfig,
  50. userTypeList
  51. } from '@/utils/auth';
  52. import Cookies from "js-cookie";
  53. import {
  54. isEnable
  55. } from '../answer_question/common/data/common';
  56. export default {
  57. data() {
  58. return {
  59. // 状态栏高度
  60. statusBarHeight: 0,
  61. // 导航栏高度
  62. navBarHeight: 82 + 11,
  63. value: '',
  64. userTypeList,
  65. // 校验表单数据
  66. formData: {
  67. user_type: '',
  68. user_name: '',
  69. password: '',
  70. is_password_md5: 'true',
  71. verification_code_image_id: '',
  72. verification_code_image_text: ''
  73. },
  74. image_content_base64: '',
  75. // 校验规则
  76. rules: {
  77. user_type: {
  78. rules: [{
  79. required: true,
  80. errorMessage: '请选择登录身份'
  81. }]
  82. },
  83. user_name: {
  84. rules: [{
  85. required: true,
  86. errorMessage: '请输入邮箱、手机号或用户名'
  87. }]
  88. },
  89. password: {
  90. rules: [{
  91. required: true,
  92. errorMessage: '请输入登录密码',
  93. }]
  94. },
  95. verification_code_image_text: {
  96. rules: [{
  97. required: true,
  98. errorMessage: '请输入验证码'
  99. }]
  100. }
  101. },
  102. placeholderStyle: "color:#555454;font-size:32rpx",
  103. login_text_styles: {
  104. color: '#555454',
  105. borderColor: '#8E8383',
  106. backgroundColor: '#f9f8f9'
  107. },
  108. share_record_id: ''
  109. };
  110. },
  111. onReady() {
  112. // 需要在onReady中设置规则
  113. this.$refs.form.setRules(this.rules);
  114. },
  115. onLoad(options) {
  116. if (options && '' != options.share_record_id) {
  117. this.share_record_id = options.share_record_id;
  118. }
  119. this.updateVerificationCode();
  120. var that = this;
  121. //有效访问令牌下无需登录
  122. uni.getStorage({
  123. key: 'AccessToken',
  124. success: function(res) {
  125. ParseAccessToken({
  126. access_token: res.data
  127. }).then(({
  128. is_effective
  129. }) => {
  130. if (is_effective == 'true') {
  131. if (that.share_record_id) {
  132. uni.navigateTo({
  133. url: '/pages/answer_question/answer/index?share_record_id=' + that.share_record_id +
  134. '&isScanCode=true'
  135. })
  136. } else {
  137. uni.switchTab({
  138. url: '/pages/tabbar/task/index'
  139. })
  140. }
  141. } else {
  142. that.getLogo();
  143. }
  144. });
  145. }
  146. })
  147. },
  148. //第一次加载时调用
  149. created() {
  150. //获取手机状态栏高度
  151. this.statusBarHeight = uni.getSystemInfoSync()['statusBarHeight'];
  152. },
  153. methods: {
  154. updateVerificationCode() {
  155. GetVerificationCodeImage().then(({
  156. image_id,
  157. image_content_base64: image
  158. }) => {
  159. this.formData.verification_code_image_id = image_id;
  160. this.image_content_base64 = image;
  161. });
  162. },
  163. getLogo() {
  164. GetLogo().then((res) => {
  165. setConfig(res);
  166. });
  167. },
  168. change(e) {
  169. this.formData.user_type = e;
  170. },
  171. submitForm() {
  172. this.$refs.form.validate((valid) => {
  173. if (valid) return false;
  174. let _form = {
  175. ...this.formData,
  176. password: md5(this.formData.password).toUpperCase()
  177. };
  178. this.$store
  179. .dispatch('user/login', _form)
  180. .then(() => {
  181. const token = getToken();
  182. if (token) {
  183. uni.setStorage({
  184. key: 'AccessToken',
  185. data: getToken().access_token
  186. });
  187. }
  188. if (this.share_record_id) {
  189. uni.navigateTo({
  190. url: '/pages/answer_question/answer/index?share_record_id=' + this.share_record_id +
  191. '&isScanCode=true'
  192. })
  193. } else {
  194. uni.switchTab({
  195. url: '/pages/tabbar/task/index'
  196. })
  197. }
  198. })
  199. .catch((res) => {
  200. this.updateVerificationCode();
  201. });
  202. })
  203. },
  204. forget() {
  205. uni.navigateTo({
  206. url: '/pages/login/Forget'
  207. })
  208. }
  209. }
  210. }
  211. </script>
  212. <style lang="scss" scoped>
  213. .login {
  214. width: 90%;
  215. margin: 172rpx auto 0;
  216. .title-big {
  217. margin: 0;
  218. font-size: 74rpx;
  219. font-weight: 700;
  220. line-height: 94rpx;
  221. color: #000;
  222. }
  223. .title {
  224. margin: 16rpx 0 72rpx;
  225. font-size: 56rpx;
  226. font-weight: 400;
  227. line-height: 70rpx;
  228. color: #000;
  229. }
  230. .uni-forms-item:first-child {
  231. border: 1px solid #8E8383;
  232. background-color: $uni-bg-color-grey;
  233. border-radius: 8rpx;
  234. /deep/ .uni-select {
  235. border: 0;
  236. background-color: $uni-bg-color-grey;
  237. }
  238. /deep/ .uni-select__input-placeholder {
  239. color: #555454;
  240. background-color: $uni-bg-color-grey;
  241. font-size: 32rpx;
  242. }
  243. }
  244. .login-text {
  245. display: flex;
  246. height: 98rpx;
  247. margin: -4rpx auto;
  248. }
  249. .verification-code {
  250. float: left;
  251. width: calc(100% - 300rpx);
  252. }
  253. image {
  254. margin-top: -4rpx;
  255. float: right;
  256. width: 264rpx;
  257. }
  258. .forget {
  259. clear: both;
  260. text-align: right;
  261. margin-bottom: 46rpx;
  262. color: #000000;
  263. border-radius: 8rpx;
  264. margin-top: -16rpx;
  265. }
  266. .submit {
  267. background-color: #175DFF;
  268. width: 100%;
  269. height: 98rpx;
  270. border-radius: 10rpx;
  271. font-size: 36rpx;
  272. color: #fff;
  273. }
  274. }
  275. </style>