login.uvue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view class=" normal-login-container my-page">
  3. <view class="logo-content align-center justify-center flex">
  4. <image class="my-image" style="width: 150rpx;height: 150rpx;" :src="(globalConfig['appInfo'] as UTSJSONObject)['logo'] as string" mode="widthFix">
  5. </image>
  6. <text class="title">系统登录</text>
  7. </view>
  8. <view class=" login-form-content">
  9. <view class=" input-item flex align-center uni-row">
  10. <view class=" icon"></view>
  11. <input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
  12. </view>
  13. <view class=" input-item flex align-center uni-row">
  14. <view class="icon"></view>
  15. <input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
  16. </view>
  17. <!--
  18. <view class="input-item flex align-center uni-row" style="width: 60%;margin-top: 10px;" v-if="captchaEnabled">
  19. <view class=" iconfont icon-code icon"></view>
  20. <input v-model="loginForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />
  21. <view class=" login-code">
  22. <image :src="codeUrl" @click="getCode" class="login-code-img my-image"></image>
  23. </view>
  24. </view> -->
  25. <view>
  26. <button @click="handleLogin" class="login-btn block bg-blue lg round">登录</button>
  27. </view>
  28. <view class=" reg" v-if="register">
  29. <text class="text-grey1">没有账号?</text>
  30. <text @click="handleUserRegister" class="text-blue">立即注册</text>
  31. </view>
  32. <view class=" xieyi justify-center flex uni-row">
  33. <text class="text-grey1 font-14">登录即代表同意</text>
  34. <text @click="handleUserAgrement" class="text-blue font-14">《用户协议》</text>
  35. <text @click="handlePrivacy" class="text-blue font-14">《隐私协议》</text>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script lang="uts">
  41. import { GlobalConfig } from '../config'
  42. import { getCodeImg } from '@/api/login'
  43. import {Login,GetInfo} from '@/store'
  44. type LoginForm={
  45. username: string,
  46. password: string,
  47. code: string,
  48. uuid: string
  49. }
  50. export default {
  51. data() {
  52. return {
  53. codeUrl: "" as string,
  54. captchaEnabled: false as boolean,
  55. // 用户注册开关
  56. register: true as boolean,
  57. globalConfig: getApp().globalData.config as UTSJSONObject,
  58. loginForm: {
  59. username: "admin",
  60. password: "admin123",
  61. code: "",
  62. uuid: ''
  63. } as UTSJSONObject
  64. }
  65. },
  66. created() {
  67. //this.getCode()
  68. },
  69. methods: {
  70. // 用户注册
  71. handleUserRegister() {
  72. uni.redirectTo({
  73. url: '/pages/register'
  74. });
  75. },
  76. // 隐私协议
  77. handlePrivacy() {
  78. let appInfo = this.globalConfig['appInfo'] as UTSJSONObject;
  79. let agreements = appInfo['agreements'] as UTSJSONObject[];
  80. let site = agreements[0] as UTSJSONObject;
  81. uni.navigateTo({
  82. url: `/pages/common/webview/index?title=${site.title}&url=${site.url}`
  83. });
  84. },
  85. // 用户协议
  86. handleUserAgrement() {
  87. let appInfo = this.globalConfig['appInfo'] as UTSJSONObject;
  88. let agreements = appInfo['agreements'] as UTSJSONObject[];
  89. let site = agreements[1] as UTSJSONObject;
  90. uni.navigateTo({
  91. url: `/pages/common/webview/index?title=${site.title}&url=${site.url}`
  92. });
  93. },
  94. // getCode() {
  95. // getCodeImg().then((res:UTSJSONObject) => {
  96. // this.captchaEnabled = res['captchaEnabled'] != null ? res['captchaEnabled'] as boolean : true
  97. // if (this.captchaEnabled) {
  98. // this.codeUrl = 'data:image/gif;base64,' + res.img as string
  99. // this.loginForm.uuid = res.uuid as string
  100. // }
  101. // })
  102. //},
  103. // 登录方法
  104. async handleLogin() {
  105. if (this.loginForm.username === "") {
  106. uni.showToast({
  107. title: '请输入您的账号',
  108. icon: 'error',
  109. duration: 2000
  110. });
  111. } else if (this.loginForm.password === "") {
  112. uni.showToast({
  113. title: '请输入您的密码',
  114. icon: 'error',
  115. duration: 2000
  116. });
  117. }
  118. /*
  119. else if (this.loginForm.code === "" && this.captchaEnabled) {
  120. uni.showToast({
  121. title: '请输入验证码',
  122. icon: 'error',
  123. duration: 2000
  124. });
  125. }
  126. */
  127. else {
  128. uni.showLoading({
  129. title: '登录中,请耐心等待...'
  130. });
  131. this.pwdLogin()
  132. }
  133. },
  134. // 密码登录
  135. async pwdLogin() {
  136. Login(this.loginForm).then(() => {
  137. uni.hideLoading();
  138. this.loginSuccess()
  139. }).catch((e) => {
  140. console.log(e)
  141. if (this.captchaEnabled) {
  142. //this.getCode()
  143. }
  144. })
  145. },
  146. // 登录成功后,处理函数
  147. loginSuccess() {
  148. // 设置用户信息
  149. GetInfo().then(() => {
  150. uni.reLaunch({
  151. url: '/pages/work/index'
  152. });
  153. })
  154. }
  155. }
  156. }
  157. </script>
  158. <style lang="scss">
  159. .my-page {
  160. background-color: #ffffff;
  161. width: 100%;
  162. height: 100%;
  163. }
  164. .normal-login-container {
  165. width: 100%;
  166. align-items: center;
  167. justify-content: center;
  168. .logo-content {
  169. width: 100%;
  170. padding-top: 15%;
  171. .my-image {
  172. border-radius: 4px;
  173. }
  174. .title {
  175. text-align: center;
  176. margin-left: 10px;
  177. font-size: 21px;
  178. margin-top: 15rpx;
  179. }
  180. }
  181. .login-form-content {
  182. /* #ifdef APP-NVUE */
  183. text-align: center;
  184. /* #endif */
  185. margin: 20px auto;
  186. margin-top: 15%;
  187. width: 80%;
  188. .input-item {
  189. margin: 10px 0;
  190. background-color: #f5f6f7;
  191. height: 45px;
  192. border-radius: 20px;
  193. .icon {
  194. /* #ifdef APP-NVUE */
  195. font-size: 38rpx;
  196. color: #999;
  197. /* #endif */
  198. margin-left: 10px;
  199. }
  200. .input {
  201. width: 100%;
  202. font-size: 14px;
  203. /* #ifdef APP-NVUE */
  204. line-height: 20px;
  205. /* #endif */
  206. text-align: left;
  207. padding-left: 15px;
  208. }
  209. }
  210. .login-btn {
  211. margin-top: 30px;
  212. height: 45px;
  213. }
  214. .reg {
  215. margin-top: 15px;
  216. flex-direction: row;
  217. }
  218. .xieyi {
  219. /* #ifdef APP-NVUE */
  220. color: #333;
  221. /* #endif */
  222. margin-top: 20px;
  223. }
  224. .login-code {
  225. height: 38px;
  226. width: 200rpx;
  227. .login-code-img {
  228. height: 38px;
  229. position: fixed;
  230. margin-left: -20px;
  231. width: 200rpx;
  232. }
  233. }
  234. }
  235. }
  236. </style>