login.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <view style="height: 100vh;">
  3. <view class="status_bar"></view>
  4. <view class="logo">
  5. <image src="../../static/image/login/8eef2e54055a5b072a5dc000919a7ae.png" mode=""></image>
  6. </view>
  7. <form @submit="formSubmit">
  8. <view class="uni-form-item uni-column">
  9. <view class="username">
  10. <u-icon name="account" size="36" style="margin-right:30rpx;color: #72CD9C;"></u-icon>
  11. <u-input class="uni-input" name="username" v-model="formdata.username" placeholder-class="icon iconfont icon-bianji1"
  12. placeholder="请输入用户名" @blur="blur"/>
  13. </view>
  14. <view class="passwold">
  15. <u-icon name="lock" size="36" style="margin-right:30rpx;color: #72CD9C;"></u-icon>
  16. <u-input v-model="formdata.passwold" type="password" :password-icon="true" :clearable="false" placeholder="请输入密码"
  17. @confirm="formSubmit" @input="passwoldddata" />
  18. </view>
  19. <view class="aboutpass">
  20. <u-checkbox-group>
  21. <u-checkbox v-model="checked" :label-disabled="false" size="22" @change="rempass">记住密码</u-checkbox>
  22. </u-checkbox-group>
  23. </view>
  24. <view class="uni-btn-v">
  25. <button form-type="submit">登 录</button>
  26. </view>
  27. </view>
  28. </form>
  29. <view class="bg">
  30. <image src="../../static/image/login/850c9307f4ef2d7dc6db1049711ab55.jpg" mode=""></image>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. data() {
  37. return {
  38. checked: false,
  39. formdata: {
  40. username: '',
  41. passwold: ''
  42. }
  43. }
  44. },
  45. onLoad() {
  46. uni.getStorage({
  47. key: 'user_pass',
  48. success: (res) => {
  49. if(res.data){
  50. this.formdata.passwold = res.data
  51. this.checked =true
  52. }else{
  53. this.checked =false
  54. }
  55. }
  56. })
  57. uni.getStorage({
  58. key: 'user_name',
  59. success: (res) => {
  60. this.formdata.username = res.data
  61. }
  62. })
  63. },
  64. onShow(){
  65. uni.getStorage({
  66. key: 'session_key',
  67. success: (res) => {
  68. if(res.data!=""){
  69. uni.switchTab({
  70. url: "../index/index"
  71. })
  72. }
  73. }
  74. })
  75. },
  76. methods: {
  77. async formSubmit() {
  78. const res = await this.$myRequest({
  79. url: '/api/api_gateway?method=user.login.login_user',
  80. data: {
  81. username: this.formdata.username,
  82. password: this.formdata.passwold
  83. }
  84. })
  85. let session_key = res.session_key
  86. uni.setStorage({
  87. key: 'session_key',
  88. data: session_key,
  89. success: () => {
  90. uni.switchTab({
  91. url: "../index/index"
  92. })
  93. }
  94. })
  95. },
  96. passwoldddata() {
  97. this.formdata.passwold = this.formdata.passwold.replace(/[\u4E00-\u9FA5]/g, '')
  98. },
  99. rempass(val) {
  100. if(val.value){
  101. uni.setStorage({
  102. key: 'user_pass',
  103. data: this.formdata.passwold,
  104. success: function() {
  105. console.log('success');
  106. }
  107. })
  108. }else{
  109. uni.removeStorage({
  110. key: 'user_pass',
  111. success: function() {
  112. console.log('success');
  113. }
  114. })
  115. }
  116. },
  117. blur(val){
  118. uni.setStorage({
  119. key: 'user_name',
  120. data: val,
  121. success: function() {
  122. console.log('success');
  123. }
  124. })
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang="scss">
  130. .logo {
  131. width: 100%;
  132. height: 340rpx;
  133. text-align: center;
  134. display: flex;
  135. align-items: center;
  136. padding-top: 240rpx;
  137. image {
  138. width: 280rpx;
  139. margin: 0 auto;
  140. height: 120rpx;
  141. }
  142. }
  143. .bg {
  144. width: 100%;
  145. position: fixed;
  146. bottom: 0;
  147. z-index: -1;
  148. image {
  149. width: 100%;
  150. }
  151. }
  152. /deep/.u-input__right-icon {
  153. line-height: 35px !important;
  154. }
  155. .uni-form-item {
  156. width: 100%;
  157. .username {
  158. width: 80%;
  159. margin: 0 auto;
  160. display: flex;
  161. margin-bottom: 40rpx;
  162. padding-bottom: 10rpx;
  163. border-bottom: 2rpx solid #C3C3C3;
  164. }
  165. .passwold {
  166. width: 80%;
  167. margin: 0 auto;
  168. display: flex;
  169. margin-bottom: 40rpx;
  170. padding-bottom: 10rpx;
  171. border-bottom: 2rpx solid #C3C3C3;
  172. }
  173. .aboutpass {
  174. width: 80%;
  175. margin: 0 auto;
  176. display: flex;
  177. justify-content: flex-end;
  178. p {
  179. color: #C0C0C0;
  180. font-size: 28rpx;
  181. }
  182. /deep/.u-checkbox__label {
  183. font-size: 28rpx;
  184. color: #C0C0C0;
  185. margin-right: 0;
  186. }
  187. }
  188. .uni-btn-v {
  189. width: 80%;
  190. margin: 112rpx auto 0;
  191. position: relative;
  192. z-index: 100;
  193. button {
  194. width: 100%;
  195. height: 72rpx;
  196. line-height: 75rpx;
  197. background-color: #5DC18B;
  198. color: #FFFFFF;
  199. border-radius: 36rpx;
  200. font-size: 28rpx;
  201. }
  202. }
  203. }
  204. </style>