login.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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="20" 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 @click.stop='userAgreement'>《用户协议》</text>
  36. </view>
  37. </view>
  38. <u-modal :show="show" :title="title" @confirm="confirm" :zoom="true" :asyncClose="true">
  39. <view class="slot-content">
  40. <rich-text :nodes="content"></rich-text>
  41. </view>
  42. </u-modal>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. show: false,
  50. title: '用户隐私',
  51. content: `1、我们会遵循隐私声明收集、使用您的信息,但不会仅因您同意本隐私声明而采用强制捆绑的方式一揽子收集个人信息。<br>2、当您使用或开启相关功能或使用服务时,为实现功能、服务所必需,我们会收集、使用相关信息。除非是为实现基本业务功能或根据法律法规要求所必需的必要信息,您均可以拒绝提供且不影响其他功能或服务。<br>3、我们将在隐私声明中逐项说明哪些是必要信息。<br>4、当您使用或开启相关功能或使用服务时,为实现功能、服务所必需,我们会收集、使用相关信息。除非是为实现基本业务功能或根据法律法规要求所必需的必要信息,您均可以拒绝提供且不影响其他功能或服务。我们将在隐私声明中逐项说明哪些是必要信息。`,
  52. loading: false,
  53. openPassword: true,
  54. name: true,
  55. active: true,
  56. loginMsg: {
  57. userName: '',
  58. password: ''
  59. // userName: 'admin',
  60. // password: 'rW8[cD1!bQ6{'
  61. }
  62. }
  63. },
  64. methods: {
  65. onLoad() {
  66. if (uni.getStorageSync('Token')) {
  67. uni.switchTab({
  68. url: "/pages/mine/mine"
  69. })
  70. }
  71. },
  72. confirm() {
  73. setTimeout(() => {
  74. // 3秒后自动关闭
  75. this.active = false
  76. this.show = false;
  77. }, 1500)
  78. },
  79. userAgreement() {
  80. //用户协议
  81. this.show = true
  82. },
  83. pwdIcon() {
  84. this.name = !this.name
  85. this.openPassword = !this.openPassword
  86. },
  87. async login() {
  88. if(!this.loginMsg.userName||!this.loginMsg.password){
  89. return this.$u.toast(`账号密码不能为空`)
  90. }
  91. console.log (1);
  92. this.loading = true
  93. try {
  94. await uni.$http.post("/api/v1/user/login", this.loginMsg).then(res => {
  95. if (res.data.code === 200) {
  96. console.log(res);
  97. setTimeout(() => {
  98. this.$u.toast(`登录成功`)
  99. // this.loading = false
  100. uni.setStorageSync('userId', res.data.data.userId)
  101. uni.setStorageSync('Token', res.data.data.tokenValue)
  102. uni.setStorageSync('id', res.data.data.permissions[0].id)
  103. uni.setStorageSync('userName', this.loginMsg.userName)
  104. this.getProjectList()
  105. uni.switchTab({
  106. url: "/pages/index/index"
  107. })
  108. }, 2000)
  109. } else {
  110. uni.$showMsg('账号或者密码错误')
  111. this.loading = false
  112. }
  113. })
  114. } catch (err) {
  115. console.log(err)
  116. setTimeout(() => {
  117. this.loading = false
  118. }, 2000)
  119. } finally {
  120. setTimeout(() => {
  121. this.loading = false
  122. }, 2000)
  123. }
  124. // await uni.$http.post("/api/v1/user/login", this.loginMsg).then(res=>{
  125. // if (res.data.code === 200) {
  126. // setTimeout(() => {
  127. // this.$u.toast(`登录成功`)
  128. // this.loading = false
  129. // uni.setStorageSync('userId', res.data.data.userId)
  130. // uni.setStorageSync('Token', res.data.data.tokenValue)
  131. // uni.setStorageSync('id', res.data.data.permissions[0].id)
  132. // this.getProjectList()
  133. // uni.switchTab({
  134. // url: "/pages/index/index"
  135. // })
  136. // }, 1000)
  137. // } else {
  138. // uni.$showMsg('账号或者密码错误')
  139. // this.loading = false
  140. // }
  141. // })
  142. // console.log(data);
  143. },
  144. changActive() {
  145. this.active = !this.active
  146. },
  147. toIndex() {
  148. if (this.active == true) {
  149. uni.showModal({
  150. title: '温馨提示',
  151. content: '隐私未勾选,点击确定自动勾选登录',
  152. success: res => {
  153. if (res.confirm) {
  154. this.active = false
  155. this.login()
  156. }
  157. }
  158. })
  159. } else {
  160. this.login()
  161. }
  162. },
  163. async getProjectList() {
  164. let msg = {
  165. userId: uni.getStorageSync('userId'),
  166. pageNo: 1,
  167. pageSize: 100
  168. }
  169. const {
  170. data: res
  171. } = await uni.$http.post('/api/v1/test/testProject/queryByCondition', msg)
  172. // console.log(res.data.records[0].id);
  173. uni.setStorageSync('testProjectId', res.data.records[0].id)
  174. uni.setStorageSync('gatewayDeviceId', res.data.records[0].gatewayDeviceId)
  175. }
  176. },
  177. }
  178. </script>
  179. <style lang="scss" scoped>
  180. .head {
  181. width: 100vw;
  182. height: calc(40vh - 30px);
  183. // background-color: red;
  184. }
  185. .login {
  186. height: 60vh;
  187. width: 100vw;
  188. background-color: #eee;
  189. border-top-left-radius: 20px;
  190. border-top-right-radius: 20px;
  191. .title {
  192. text-align: center;
  193. font-size: 30px;
  194. padding: 30px 0 10px 0;
  195. }
  196. .login-msg {
  197. height: 20vh;
  198. width: calc(100vw - 60px);
  199. margin: 0 20px;
  200. background-color: #fdfdfd;
  201. border-radius: 20px;
  202. display: flex;
  203. flex-direction: column;
  204. justify-content: space-evenly;
  205. padding: 10px;
  206. .username {
  207. display: flex;
  208. justify-content: center;
  209. align-items: center;
  210. input {
  211. // margin-left: 2px;
  212. width: 100%;
  213. height: 7vh;
  214. // border: 1px solid black;
  215. // border: none;
  216. // text-align: center;
  217. outline: none;
  218. text-indent: 10px; //缩进,输入的内容
  219. padding-left: 10px;
  220. border-bottom: 1px solid #eee // width: 80%;
  221. }
  222. }
  223. }
  224. .loginBtn {
  225. width: 40vw;
  226. margin: 3vw 30vw;
  227. }
  228. .agreeMsg {
  229. margin-top: 20px;
  230. font-size: 13px;
  231. text-align: center;
  232. .icon {
  233. vertical-align: middle;
  234. }
  235. text {
  236. color: #1b89fb;
  237. }
  238. }
  239. }
  240. </style>