No Description

login.vue 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <view class="login">
  3. <view class="content">
  4. <!-- 头部logo -->
  5. <view class="header">
  6. <image :src="logoImage"></image>
  7. </view>
  8. <!-- 主体表单 -->
  9. <view class="main">
  10. <wInput v-model="phoneData" type="text" maxlength="11" placeholder="用户名" :focus="isFocus"></wInput>
  11. <wInput v-model="passData" type="password" maxlength="11" placeholder="密码"></wInput>
  12. <wInput v-model="verificationData" type="text" maxlength="11" placeholder="验证码" :focus="isFocus">
  13. </wInput>
  14. </view>
  15. <wButton class="wbutton" text="获取验证码" :rotate="isVerification" @click="sendVerification"></wButton>
  16. <wButton class="wbutton" text="登 录" :rotate="isRotate" @click="startLogin"></wButton>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. let _this;
  22. import wInput from '../../components/watch-login/watch-input.vue' //input
  23. import wButton from '../../components/watch-login/watch-button.vue' //button
  24. import CryptoJS from '../../node_modules/crypto-js/crypto-js.js'
  25. import md5 from '../../node_modules/md5/md5.js'
  26. export default {
  27. data() {
  28. return {
  29. //logo图片 base64
  30. logoImage: '../../static/login-icon.png',
  31. phoneData: '', //用户/电话
  32. passData: '', //密码
  33. verificationData: '', //验证码
  34. isRotate: false, //是否加载旋转
  35. isVerification: false,
  36. isFocus: true // 是否聚焦
  37. };
  38. },
  39. components: {
  40. wInput,
  41. wButton,
  42. },
  43. onLoad() {
  44. this.isLogin();
  45. uni.showToast({
  46. icon: 'none',
  47. position: 'bottom',
  48. title: process.env.NODE_ENV
  49. });
  50. },
  51. methods: {
  52. isLogin() {
  53. //判断缓存中是否登录过,直接登录
  54. try {
  55. const value = uni.getStorageSync('token');
  56. if (value) {
  57. //有登录信息
  58. console.log("已登录用户:", value);
  59. uni.switchTab({
  60. url: '/pages/myTask/myTask'
  61. });
  62. }
  63. } catch (e) {
  64. // error
  65. }
  66. },
  67. sendVerification() {
  68. this.isVerification = true
  69. console.log(this.passData)
  70. console.log(this.encryptPassWord(this.passData).toString())
  71. const params = {
  72. "usercode": this.phoneData,
  73. "Password": this.encryptPassWord(this.passData).toString(),
  74. "LoginTime": this.$mHelper.CurentTime(),
  75. }
  76. this.$http.post("/Login/SendCode", params).then((response) => {
  77. if (response.state.toLowerCase() === 'success') {
  78. this.isVerification = false
  79. uni.showModal({
  80. content: '验证码发送成功',
  81. showCancel: false
  82. });
  83. }
  84. }).catch((e) => {
  85. uni.showModal({
  86. content: e,
  87. showCancel: false
  88. });
  89. this.isVerification = false
  90. console.log(e)
  91. })
  92. },
  93. startLogin(e) {
  94. //登录
  95. if (this.isRotate) {
  96. //判断是否加载中,避免重复点击请求
  97. return false;
  98. }
  99. if (this.phoneData.length == "") {
  100. uni.showToast({
  101. icon: 'none',
  102. position: 'bottom',
  103. title: '用户名不能为空'
  104. });
  105. return;
  106. }
  107. if (this.passData.length == "") {
  108. uni.showToast({
  109. icon: 'none',
  110. position: 'bottom',
  111. title: '密码不能为空'
  112. });
  113. return;
  114. }
  115. this.isRotate = true
  116. const params = {
  117. "username": this.phoneData,
  118. "password": this.encryptPassWord(this.passData).toString(),
  119. "Code": this.verificationData,
  120. "LoginTime": this.$mHelper.CurentTime(),
  121. }
  122. this.$http.post("/Login/login", params).then((response) => {
  123. if (response.state.toLowerCase() === 'success') {
  124. this.isRotate = false
  125. uni.setStorageSync('Username', this.phoneData)
  126. uni.setStorageSync('Password', this.passData)
  127. uni.setStorageSync('token', response.data.token)
  128. this.getNowUser()
  129. }
  130. }).catch((e) => {
  131. uni.showModal({
  132. content: e,
  133. showCancel: false
  134. });
  135. this.isRotate = false
  136. console.log(e)
  137. })
  138. },
  139. // 获取用户信息
  140. getNowUser() {
  141. const params = {
  142. token: uni.getStorageSync("token"),
  143. }
  144. this.$http.get("UserAccount/GetNowUser", params).then((response) => {
  145. if (response.state.toLowerCase() === "success") {
  146. const data = response.data
  147. uni.setStorageSync('roleCode', data.role.F_RoleCode)
  148. uni.setStorageSync('userName', data.user.F_UserName)
  149. uni.setStorageSync('userCode', data.user.F_UserCode)
  150. const code = uni.getStorageSync("roleCode");
  151. if (code === "ZXLD"||code === "MTDD"||code === "WLDW"||code === "EJWLDW") {
  152. uni.switchTab({
  153. url: '/pages/myTask/myTask'
  154. });
  155. } else {
  156. this.$mHelper.toast("暂无操作权限");
  157. }
  158. }
  159. })
  160. .catch((e) => {
  161. this.$mHelper.toast(e);
  162. })
  163. },
  164. //密码加密
  165. encryptPassWord(passData) {
  166. const currenttime = this.$mHelper.CurentTime();
  167. const datatime = currenttime.split(' ')[1].split(':').join('')
  168. const key = CryptoJS.enc.Utf8.parse(")O[9d]6,YF}+efcaj{+8>Z'e9M" + datatime);
  169. const gl_psw = CryptoJS.enc.Utf8.parse(md5.hex_md5(this.passData));
  170. const encrypted = CryptoJS.AES.encrypt(gl_psw, key, {
  171. mode: CryptoJS.mode.ECB,
  172. padding: CryptoJS.pad.Pkcs7
  173. });
  174. return encrypted
  175. }
  176. }
  177. }
  178. </script>
  179. <style>
  180. @import url("../../components/watch-login/css/icon.css");
  181. @import url("./css/main.css");
  182. /deep/ .wbutton {
  183. margin-top: 20px;
  184. }
  185. /deep/ .main-list {
  186. margin: 10px 0px;
  187. }
  188. </style>