login.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <view class="normal-login-container" style="background-image: url('https://jianyaoji.oss-cn-hangzhou.aliyuncs.com/jianyaoji/images/login/bg.png');background-size: 100% 100%;">
  3. <view class="logo-content align-center justify-center flex">
  4. <!-- <image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix">-->
  5. <!-- </image>-->
  6. <text class="title">老药师云平台移动端登录</text>
  7. </view>
  8. <view style="position: fixed;top:1vw;left:1vh;font-size: 12px;color: white;">
  9. 版本号:{{version}}
  10. </view>
  11. <view class="login-form-content">
  12. <view class="input-item flex align-center">
  13. <view class="iconfont icon-user icon"></view>
  14. <input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
  15. </view>
  16. <view class="input-item flex align-center">
  17. <view class="iconfont icon-password icon"></view>
  18. <input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
  19. </view>
  20. <view class="input-item flex align-center" style="width: 60%;margin: 0px;" v-if="captchaEnabled">
  21. <view class="iconfont icon-code icon"></view>
  22. <input v-model="loginForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />
  23. <view class="login-code">
  24. <image :src="codeUrl" @click="getCode" class="login-code-img"></image>
  25. </view >
  26. </view>
  27. <view class="action-btn">
  28. <button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>
  29. </view>
  30. </view>
  31. <view class="xieyi text-center">
  32. <!-- <text class="text-grey1">登录即代表同意</text>-->
  33. <!-- <text @click="handleUserAgrement" class="text-blue">《用户协议》</text>-->
  34. <!-- <text @click="handlePrivacy" class="text-blue">《隐私协议》</text>-->
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import { getCodeImg } from '@/api/login'
  40. import {getToken} from "@/utils/auth";
  41. export default {
  42. data() {
  43. return {
  44. version:"",
  45. codeUrl: "",
  46. captchaEnabled: true,
  47. globalConfig: getApp().globalData.config,
  48. loginForm: {
  49. username: "",
  50. password: "",
  51. code: "",
  52. uuid: ''
  53. }
  54. }
  55. },
  56. created() {
  57. this.getVersion();
  58. this.checkLogin();
  59. },
  60. methods: {
  61. checkLogin(){
  62. let token = getToken()
  63. if(token){
  64. this.loginSuccess()
  65. }else{
  66. this.getCode()
  67. }
  68. },
  69. // 隐私协议
  70. handlePrivacy() {
  71. let site = this.globalConfig.appInfo.agreements[0]
  72. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  73. },
  74. // 用户协议
  75. handleUserAgrement() {
  76. let site = this.globalConfig.appInfo.agreements[1]
  77. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  78. },
  79. // 获取图形验证码
  80. getCode() {
  81. getCodeImg().then(res => {
  82. this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
  83. if (this.captchaEnabled) {
  84. this.codeUrl = 'data:image/gif;base64,' + res.img
  85. this.loginForm.uuid = res.uuid
  86. }
  87. })
  88. },
  89. getVersion(){
  90. let appBaseInfo = uni.getAppBaseInfo();
  91. let appVersionCode = appBaseInfo.appVersionCode;
  92. this.version = appVersionCode;
  93. },
  94. // 登录方法
  95. async handleLogin() {
  96. if (this.loginForm.username === "") {
  97. this.$modal.msgError("请输入您的账号")
  98. } else if (this.loginForm.password === "") {
  99. this.$modal.msgError("请输入您的密码")
  100. } else if (this.loginForm.code === "" && this.captchaEnabled) {
  101. this.$modal.msgError("请输入验证码")
  102. } else {
  103. this.$modal.loading("登录中,请耐心等待...")
  104. this.pwdLogin()
  105. }
  106. },
  107. // 密码登录
  108. async pwdLogin() {
  109. this.$store.dispatch('Login', this.loginForm).then(() => {
  110. this.$modal.closeLoading()
  111. this.loginSuccess()
  112. }).catch(() => {
  113. if (this.captchaEnabled) {
  114. this.getCode()
  115. }
  116. })
  117. },
  118. // 登录成功后,处理函数
  119. loginSuccess(result) {
  120. // 设置用户信息
  121. this.$store.dispatch('GetInfo').then(res => {
  122. this.$tab.reLaunch('/pages/work/index')
  123. })
  124. }
  125. }
  126. }
  127. </script>
  128. <style lang="scss">
  129. page {
  130. background-color: #ffffff;
  131. }
  132. .normal-login-container {
  133. width: 100%;
  134. position: absolute;
  135. top: 0px;
  136. bottom: 0;
  137. left:0;
  138. right: 0;
  139. .logo-content {
  140. width: 100%;
  141. font-size: 21px;
  142. text-align: center;
  143. padding-top: 15%;
  144. image {
  145. border-radius: 4px;
  146. }
  147. .title {
  148. margin-left: 10px;
  149. color: #FFFFFF;
  150. font-size: 56rpx;
  151. }
  152. }
  153. .login-form-content {
  154. text-align: center;
  155. margin: 20px auto;
  156. margin-top: 15%;
  157. width: 90%;
  158. background: white;
  159. border-radius: 30rpx;
  160. box-shadow: 0rpx 5rpx 27rpx 0rpx rgba(195,195,195,2.4);
  161. padding:10%;
  162. .input-item {
  163. margin: 20px auto;
  164. background-color: #f5f6f7;
  165. height: 45px;
  166. border-radius: 20px;
  167. .icon {
  168. font-size: 38rpx;
  169. margin-left: 10px;
  170. color: #999;
  171. }
  172. .input {
  173. width: 100%;
  174. font-size: 14px;
  175. line-height: 20px;
  176. text-align: left;
  177. padding-left: 15px;
  178. //background: rgb(224,236,255);
  179. }
  180. }
  181. .login-btn {
  182. margin-top: 40px;
  183. height: 45px;
  184. }
  185. .xieyi {
  186. color: #333;
  187. margin-top: 20px;
  188. }
  189. .login-code {
  190. height: 38px;
  191. float: right;
  192. .login-code-img {
  193. height: 38px;
  194. position: absolute;
  195. margin-left: 10px;
  196. width: 200rpx;
  197. }
  198. }
  199. }
  200. }
  201. </style>