login.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <view class="container">
  3. <!-- <view id="login_form"> -->
  4. <image class="logo" src="/static/top_login.png"></image>
  5. <el-form label-width="0px" :model="ruleForm" status-icon :rules="rules" ref="ruleForm"
  6. class="demo-ruleForm">
  7. <el-form-item prop="uname" class='uname'>
  8. <input ref="zhanghao" placeholder="请输入账号" maxlength="16" v-model="ruleForm.uname"
  9. prefix-icon="el-icon-login-user"></input>
  10. </el-form-item>
  11. <el-form-item prop="upass" class='upass'>
  12. <input ref="mima" placeholder="请输入密码" maxlength="16" type="password"
  13. v-model="ruleForm.upass" prefix-icon="el-icon-login-pass"
  14. @keyup.enter.native="submitForm('ruleForm')">
  15. </input>
  16. </el-form-item>
  17. <el-form-item class='denglv'>
  18. <button type="primary" @click="submitForm('ruleForm')">登 录</button>
  19. </el-form-item>
  20. </el-form>
  21. <!-- </view> -->
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. data() {
  27. var checkName = (rule, value, callback) => {
  28. // console.log(rule, value, callback);
  29. if (!value) {
  30. return callback(new Error('请输入账号'));
  31. }
  32. setTimeout(() => {
  33. if (value.length < 5) {
  34. callback(new Error('账号长度不小于5位'));
  35. } else {
  36. callback();
  37. }
  38. }, 30);
  39. };
  40. var validatePass = (rule, value, callback) => {
  41. // console.log(rule, value, callback);
  42. if (value === '') {
  43. callback(new Error('请输入密码'));
  44. }
  45. setTimeout(() => {
  46. if (value.length < 5) {
  47. callback(new Error('密码长度不小于5位'));
  48. } else {
  49. callback();
  50. }
  51. }, 30);
  52. };
  53. return {
  54. ruleForm: {
  55. uname: '',
  56. upass: ''
  57. },
  58. rules: {
  59. uname: [{
  60. validator: checkName,
  61. trigger: 'blur'
  62. }],
  63. upass: [{
  64. validator: validatePass,
  65. trigger: 'blur'
  66. }]
  67. }
  68. };
  69. },
  70. mounted() {
  71. this.$refs['zhanghao'].focus()
  72. },
  73. methods: {
  74. submitForm(formName) {
  75. let _this = this;
  76. let params = {}
  77. var username = String(_this.ruleForm.uname).trim()
  78. var userpass = String(_this.ruleForm.upass).trim()
  79. if (username && userpass) {
  80. params.userName = username
  81. params.password = userpass
  82. } else {
  83. _this.$message.warning('请输入账号和密码!')
  84. if (!username)
  85. _this.$refs['zhanghao'].focus()
  86. else
  87. _this.$refs['mima'].focus()
  88. return
  89. }
  90. _this.$refs[formName].validate((valid) => {
  91. _this.$axios({
  92. method: "post",
  93. url: "/diseaseRight/adminInfo/login?userName=" + username + '&password=' +
  94. userpass,
  95. headers: {
  96. 'Content-type': 'application/x-www-form-urlencoded;charset=utf-8'
  97. }
  98. })
  99. .then(res => {
  100. // console.log(res.data);
  101. if (res.data.success) {
  102. _this.$message.success(res.data.message);
  103. sessionStorage.setItem('uname', username)
  104. sessionStorage.setItem('userType', res.data.data.userType)
  105. sessionStorage.setItem('token', res.data.data.token)
  106. // if (typeof(res.data.name) == 'undefined') {
  107. // sessionStorage.setItem('unic', '未设置昵称')
  108. // } else {
  109. // sessionStorage.setItem('unic', res.data.name)
  110. // }
  111. uni.showToast({
  112. title: '成功',
  113. icon: 'success',
  114. duration: 1000
  115. })
  116. setTimeout(() => {
  117. uni.navigateTo({
  118. url: "./index",
  119. });
  120. }, 600);
  121. // _this.$router.replace('./index'); //跳转到首页
  122. // alert('成功')
  123. } else {
  124. _this.$message({
  125. showClose: true,
  126. message: "登陆异常:" + res.data.message,
  127. type: 'error'
  128. });
  129. }
  130. })
  131. .catch(err => {
  132. console.log(err);
  133. _this.$message.error('捕捉异常:' + err)
  134. })
  135. });
  136. }
  137. }
  138. }
  139. </script>
  140. <style scoped>
  141. .content {
  142. display: flex;
  143. flex-direction: column;
  144. align-items: center;
  145. justify-content: center;
  146. }
  147. .logo {
  148. height: 212px;
  149. width: 375px;
  150. margin-top: 0rpx;
  151. margin-left: 10px;
  152. margin-right: auto;
  153. }
  154. /* >>>.el-input el-input--prefix{
  155. height: 30px;
  156. margin-left: 80px;
  157. margin-top: 10px;
  158. }
  159. >>>.el-form-item__content{
  160. margin-left: 80px;
  161. } */
  162. .uname{
  163. margin-left: 131rpx;
  164. margin-top: 22rpx;
  165. width: 468rpx;
  166. height: 75rpx;
  167. border: #555555 1px solid;
  168. }
  169. .upass{
  170. margin-left: 131rpx;
  171. margin-top: 60rpx;
  172. width: 468rpx;
  173. height: 75rpx;
  174. border: #555555 1px solid;
  175. }
  176. .denglv{
  177. margin-left: 163rpx;
  178. margin-top: 48rpx;
  179. width: 468rpx;
  180. width: 400rpx;
  181. height: 105rpx;
  182. border-radius: 10rpx;
  183. }
  184. </style>