login.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. console.log(res)
  69. if(res.data!=""){
  70. uni.switchTab({
  71. url: "../index/index"
  72. })
  73. }
  74. }
  75. })
  76. },
  77. methods: {
  78. async formSubmit() {
  79. const res = await this.$myRequest({
  80. url: '/api/api_gateway?method=user.login.login_user',
  81. data: {
  82. username: this.formdata.username,
  83. password: this.formdata.passwold
  84. }
  85. })
  86. let session_key = res.session_key
  87. uni.setStorage({
  88. key: 'session_key',
  89. data: session_key,
  90. success: () => {
  91. uni.switchTab({
  92. url: "../index/index"
  93. })
  94. }
  95. })
  96. },
  97. passwoldddata() {
  98. this.formdata.passwold = this.formdata.passwold.replace(/[\u4E00-\u9FA5]/g, '')
  99. },
  100. rempass(val) {
  101. if(val.value){
  102. uni.setStorage({
  103. key: 'user_pass',
  104. data: this.formdata.passwold,
  105. success: function() {
  106. console.log('success');
  107. }
  108. })
  109. }else{
  110. uni.removeStorage({
  111. key: 'user_pass',
  112. success: function() {
  113. console.log('success');
  114. }
  115. })
  116. }
  117. },
  118. blur(val){
  119. uni.setStorage({
  120. key: 'user_name',
  121. data: val,
  122. success: function() {
  123. console.log('success');
  124. }
  125. })
  126. }
  127. }
  128. }
  129. </script>
  130. <style lang="scss">
  131. .logo {
  132. width: 100%;
  133. height: 340rpx;
  134. text-align: center;
  135. display: flex;
  136. align-items: center;
  137. padding-top: 240rpx;
  138. image {
  139. width: 280rpx;
  140. margin: 0 auto;
  141. height: 120rpx;
  142. }
  143. }
  144. .bg {
  145. width: 100%;
  146. position: fixed;
  147. bottom: 0;
  148. z-index: -1;
  149. image {
  150. width: 100%;
  151. }
  152. }
  153. /deep/.u-input__right-icon {
  154. line-height: 35px !important;
  155. }
  156. .uni-form-item {
  157. width: 100%;
  158. .username {
  159. width: 80%;
  160. margin: 0 auto;
  161. display: flex;
  162. margin-bottom: 40rpx;
  163. padding-bottom: 10rpx;
  164. border-bottom: 2rpx solid #C3C3C3;
  165. }
  166. .passwold {
  167. width: 80%;
  168. margin: 0 auto;
  169. display: flex;
  170. margin-bottom: 40rpx;
  171. padding-bottom: 10rpx;
  172. border-bottom: 2rpx solid #C3C3C3;
  173. }
  174. .aboutpass {
  175. width: 80%;
  176. margin: 0 auto;
  177. display: flex;
  178. justify-content: flex-end;
  179. p {
  180. color: #C0C0C0;
  181. font-size: 28rpx;
  182. }
  183. /deep/.u-checkbox__label {
  184. font-size: 28rpx;
  185. color: #C0C0C0;
  186. margin-right: 0;
  187. }
  188. }
  189. .uni-btn-v {
  190. width: 80%;
  191. margin: 112rpx auto 0;
  192. position: relative;
  193. z-index: 100;
  194. button {
  195. width: 100%;
  196. height: 72rpx;
  197. line-height: 75rpx;
  198. background-color: #5DC18B;
  199. color: #FFFFFF;
  200. border-radius: 36rpx;
  201. font-size: 28rpx;
  202. }
  203. }
  204. }
  205. </style>