login.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <view>
  3. <view class="head" style="display: flex;justify-content: center;align-items: center;">
  4. <image style="width: 100;height: 100%;"
  5. src="https://www.zhisheji.com/uc_server/data/avatar/000/19/68/09_avatar_small.jpg?time=1527483060"
  6. mode=""></image>
  7. </view>
  8. <!-- -->
  9. <view class="login">
  10. <view class="title">
  11. 登录
  12. </view>
  13. <view class="login-msg">
  14. <view class="username">
  15. <u-icon name="account-fill" color="#2979ff" size="28"></u-icon>
  16. <input v-model="loginMsg.userName" maxlength="10" type="text" placeholder="请输入账号">
  17. <view style="width: 28px;height: 28px;">
  18. </view>
  19. </view>
  20. <view class="username">
  21. <u-icon name="lock-fill" color="#2979ff" size="28"></u-icon>
  22. <input :password="openPassword" v-model="loginMsg.password" maxlength="20" placeholder="请输入密码">
  23. <view class="pwdIcon" @click="pwdIcon">
  24. <u-icon v-if="name" name="eye-off" size="28"></u-icon>
  25. <u-icon v-else name="eye-fill" size="28"></u-icon>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="loginBtn" @click="toIndex">
  30. <u-button :loading="loading" color="#19334a" shape="circle" type="primary" size="large">登录</u-button>
  31. </view>
  32. <view class="agreeMsg" @click="changActive">
  33. <uni-icons class="icon" v-if="active" type="circle" size="16" color="#999"></uni-icons>
  34. <uni-icons class="icon" v-else type="checkmarkempty" size="16" color="#1296db"></uni-icons>
  35. 登录即代表同意<text>《用户协议》</text><text>《隐私协议》</text>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. data() {
  43. return {
  44. loading: false,
  45. openPassword: true,
  46. name: true,
  47. active: false,
  48. loginMsg: {
  49. userName: 'testY',
  50. password: 'yy1021..'
  51. // userName: 'admin',
  52. // password: 'rW8[cD1!bQ6{'
  53. }
  54. }
  55. },
  56. methods: {
  57. pwdIcon() {
  58. this.name = !this.name
  59. this.openPassword = !this.openPassword
  60. },
  61. async login() {
  62. this.loading = true
  63. try {
  64. await uni.$http.post("/api/v1/user/login", this.loginMsg).then(res => {
  65. if (res.data.code === 200) {
  66. setTimeout(() => {
  67. this.$u.toast(`登录成功`)
  68. // this.loading = false
  69. uni.setStorageSync('userId', res.data.data.userId)
  70. uni.setStorageSync('Token', res.data.data.tokenValue)
  71. uni.setStorageSync('id', res.data.data.permissions[0].id)
  72. uni.setStorageSync('userName', this.loginMsg.userName)
  73. this.getProjectList()
  74. uni.switchTab({
  75. url: "/pages/index/index"
  76. })
  77. }, 2000)
  78. } else {
  79. uni.$showMsg('账号或者密码错误')
  80. this.loading = false
  81. }
  82. })
  83. } catch (err) {
  84. console.log(err)
  85. setTimeout(() => {
  86. this.loading = false
  87. }, 2000)
  88. } finally {
  89. setTimeout(() => {
  90. this.loading = false
  91. }, 2000)
  92. }
  93. // await uni.$http.post("/api/v1/user/login", this.loginMsg).then(res=>{
  94. // if (res.data.code === 200) {
  95. // setTimeout(() => {
  96. // this.$u.toast(`登录成功`)
  97. // this.loading = false
  98. // uni.setStorageSync('userId', res.data.data.userId)
  99. // uni.setStorageSync('Token', res.data.data.tokenValue)
  100. // uni.setStorageSync('id', res.data.data.permissions[0].id)
  101. // this.getProjectList()
  102. // uni.switchTab({
  103. // url: "/pages/index/index"
  104. // })
  105. // }, 1000)
  106. // } else {
  107. // uni.$showMsg('账号或者密码错误')
  108. // this.loading = false
  109. // }
  110. // })
  111. // console.log(data);
  112. },
  113. changActive() {
  114. this.active = !this.active
  115. },
  116. toIndex() {
  117. if (this.active == true) {
  118. uni.showModal({
  119. title: '温馨提示',
  120. content: '隐私未勾选,点击确定自动勾选登录',
  121. success: res => {
  122. if (res.confirm) {
  123. this.active = false
  124. this.login()
  125. }
  126. }
  127. })
  128. } else {
  129. this.login()
  130. }
  131. },
  132. async getProjectList() {
  133. let msg = {
  134. userId: uni.getStorageSync('userId'),
  135. pageNo: 1,
  136. pageSize: 100
  137. }
  138. const {
  139. data: res
  140. } = await uni.$http.post('/api/v1/test/testProject/queryByCondition', msg)
  141. // console.log(res.data.records[0].id);
  142. uni.setStorageSync('testProjectId', res.data.records[0].id)
  143. uni.setStorageSync('gatewayDeviceId', res.data.records[0].gatewayDeviceId)
  144. }
  145. },
  146. }
  147. </script>
  148. <style lang="scss" scoped>
  149. .head {
  150. width: 100vw;
  151. height: calc(40vh - 30px);
  152. // background-color: red;
  153. }
  154. .login {
  155. height: 60vh;
  156. width: 100vw;
  157. background-color: #eee;
  158. border-top-left-radius: 20px;
  159. border-top-right-radius: 20px;
  160. .title {
  161. text-align: center;
  162. font-size: 30px;
  163. padding: 30px 0 10px 0;
  164. }
  165. .login-msg {
  166. height: 20vh;
  167. width: calc(100vw - 60px);
  168. margin: 0 20px;
  169. background-color: #fdfdfd;
  170. border-radius: 20px;
  171. display: flex;
  172. flex-direction: column;
  173. justify-content: space-evenly;
  174. padding: 10px;
  175. .username {
  176. display: flex;
  177. justify-content: center;
  178. align-items: center;
  179. input {
  180. // margin-left: 2px;
  181. width: 100%;
  182. height: 7vh;
  183. // border: 1px solid black;
  184. // border: none;
  185. // text-align: center;
  186. outline: none;
  187. text-indent: 10px; //缩进,输入的内容
  188. padding-left: 10px;
  189. border-bottom: 1px solid #eee // width: 80%;
  190. }
  191. }
  192. }
  193. .loginBtn {
  194. width: 40vw;
  195. margin: 3vw 30vw;
  196. }
  197. .agreeMsg {
  198. margin-top: 20px;
  199. font-size: 13px;
  200. text-align: center;
  201. .icon {
  202. vertical-align: middle;
  203. }
  204. text {
  205. color: #1b89fb;
  206. }
  207. }
  208. }
  209. </style>