login.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <view class="content">
  3. <view class="title">
  4. <text class="thing" style="width: 100rpx;"></text>
  5. <text class="name">用户登录</text>
  6. <text class="thing" style="width: 300rpx;"></text>
  7. </view>
  8. <view class="form-box">
  9. <view class="row-input">
  10. <u-icon name="account" color="#2979ff" size="50" style="padding: 0 20rpx;"></u-icon>
  11. <input v-model="account" placeholder="请输入用户账号" maxlength="18" />
  12. </view>
  13. <view class="row-input">
  14. <u-icon name="lock" color="#2979ff" size="50" style="padding: 0 20rpx;"></u-icon>
  15. <input v-model="password" placeholder="登陆密码" :password="!isShowPassword" />
  16. <u-icon name="eye-fill" color="#2979ff" size="50" style="padding-right:20rpx" v-if="isShowPassword"
  17. @click="showOrHide"></u-icon>
  18. <u-icon name="eye-off" color="#2979ff" size="50" style="padding-right:0rpx" v-else @click="showOrHide">
  19. </u-icon>
  20. </view>
  21. <!-- <view class="rowinputcaptcha">
  22. <u-icon name="hourglass" color="#2979ff" size="50" style="padding: 0 20rpx;"></u-icon>
  23. <input class="captchainput" v-model="captcha" placeholder="验证码"/>
  24. <u--image :showLoading="true" :src="captchaPath" width="150px" height="35px" @click="getCaptcha"></u--image>
  25. </view> -->
  26. <view class="menu-link">
  27. <text @click="forget">找回密码</text>
  28. </view>
  29. <view class="login-btn" @click="loginbtn">登录</view>
  30. <view class="tip-link">
  31. 还没有账号?<text @click="register">注册</text>
  32. </view>
  33. </view>
  34. <u-toast ref="uToast" />
  35. </view>
  36. </template>
  37. <script>
  38. // function getUUID() {
  39. // return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
  40. // return (c === 'x' ? (Math.random() * 16 | 0) : ('r&0x3' | '0x8')).toString(16)
  41. // })
  42. // }
  43. //const BaseApi= require("@/http/baseApi.js");
  44. export default {
  45. data() {
  46. return {
  47. isShowPassword: false,
  48. account: '',
  49. password: '',
  50. captcha: '',
  51. uuid: '',
  52. captchaPath: '',
  53. }
  54. },
  55. onLoad() {
  56. // this.getCaptcha();
  57. },
  58. methods: {
  59. // 获取验证码
  60. // getCaptcha() {
  61. // this.uuid = getUUID();
  62. // this.captchaPath =BaseApi.BaseApi+ `/captcha?uuid=${this.uuid}`;
  63. // },
  64. loginbtn() {
  65. if (this.account == '') {
  66. this.$refs.uToast.show({
  67. type: 'error',
  68. message: "请输入账号",
  69. })
  70. // uni.showToast({
  71. // title: "请输入账号",
  72. // icon:'error',
  73. // duration: 1000,
  74. // })
  75. } else if (this.password == '') {
  76. this.$refs.uToast.show({
  77. type: 'error',
  78. message: "请输入密码",
  79. })
  80. }
  81. let formData = {
  82. username: this.account,
  83. password: this.password,
  84. // uuid:this.uuid,
  85. // captcha:this.captcha,
  86. }
  87. //登录功能
  88. this.$api.post('/login', formData)
  89. .then(res => {
  90. if (res.data.code == 0) {
  91. uni.setStorageSync('tokendata', res.data.data.token); //token
  92. uni.setStorageSync('Userinformation', formData); //用户信息
  93. //获取用户的信息,如组织架构,个人信息,权限等
  94. Promise.all([this.getpermissions(), this.getDictList(), this.getuserInfo(), ]).then(() => {
  95. uni.switchTab({
  96. url: '/pages/index/index',
  97. success: res => {},
  98. fail: () => {},
  99. complete: () => {},
  100. })
  101. });
  102. } else {
  103. this.$refs.uToast.show({
  104. type: 'error',
  105. message: "账号或者密码错误,请重新输入",
  106. })
  107. }
  108. })
  109. },
  110. getpermissions() {
  111. console.log('权限功能', )
  112. //获取用户权限功能
  113. this.$api.get('/menu/permissions', {})
  114. .then(res1 => {
  115. uni.setStorageSync('ButtonPermissions', res1.data.data); //权限列表
  116. })
  117. },
  118. getDictList() {
  119. //获取字典列表, 添加并全局变量保存
  120. this.$api.get('/all', {})
  121. .then(res => {
  122. // console.log('88888', res.data.data)
  123. uni.setStorageSync('getDictDataList', res.data.data);
  124. })
  125. },
  126. getuserInfo() {
  127. //获取用户信息
  128. this.$api.get('/user/userInfo', {})
  129. .then(res => {
  130. // console.log('88888', res.data.data)
  131. uni.setStorageSync('getuserInfo', res.data.data);
  132. })
  133. },
  134. // 密码显示/密码隐藏
  135. showOrHide() {
  136. this.isShowPassword = !this.isShowPassword
  137. },
  138. // 找回密码
  139. forget() {
  140. uni.navigateTo({
  141. url: '/pages/login/forget',
  142. success: res => {},
  143. fail: () => {},
  144. complete: () => {},
  145. })
  146. },
  147. // 注册
  148. register() {
  149. uni.navigateTo({
  150. url: '/pages/login/register',
  151. success: res => {},
  152. fail: () => {},
  153. complete: () => {},
  154. })
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss">
  160. page {
  161. background-color: #0b0c14;
  162. }
  163. .content {
  164. padding: 100rpx 40rpx;
  165. }
  166. .title {
  167. display: flex;
  168. flex-direction: column;
  169. height: 200rpx;
  170. .thing {
  171. height: 8rpx;
  172. background-image: linear-gradient(to right, #3feaea, #0168e6);
  173. }
  174. .name {
  175. font-weight: bold;
  176. font-size: 50rpx;
  177. line-height: 120rpx;
  178. background: linear-gradient(to right, #3feaea, blue);
  179. background-clip: text;
  180. color: transparent;
  181. letter-spacing: 5rpx;
  182. }
  183. }
  184. .form-box {
  185. .rowinputcaptcha {
  186. display: flex;
  187. justify-content: flex-start;
  188. align-items: center;
  189. height: 110rpx;
  190. //background-color: #2b2f41;
  191. border-radius: 8rpx;
  192. margin-bottom: 50rpx;
  193. input {
  194. width: 300rpx;
  195. font-size: 30rpx;
  196. color: #a1a2a3;
  197. }
  198. }
  199. .row-input {
  200. display: flex;
  201. justify-content: flex-start;
  202. align-items: center;
  203. height: 110rpx;
  204. background-color: #2b2f41;
  205. border-radius: 8rpx;
  206. margin-bottom: 50rpx;
  207. image {
  208. margin: 0 30rpx;
  209. flex-shrink: 0;
  210. width: 38rpx;
  211. height: 38rpx;
  212. }
  213. input {
  214. width: 460rpx;
  215. font-size: 30rpx;
  216. color: #a1a2a3;
  217. }
  218. }
  219. .menu-link {
  220. display: flex;
  221. justify-content: flex-end;
  222. align-items: center;
  223. font-size: 28rpx;
  224. color: #676c7f;
  225. }
  226. .login-btn {
  227. margin-top: 60rpx;
  228. display: flex;
  229. justify-content: center;
  230. align-items: center;
  231. font-size: 35rpx;
  232. letter-spacing: 15rpx;
  233. color: #FFFFFF;
  234. height: 110rpx;
  235. border-radius: 8rpx;
  236. background-image: linear-gradient(to right, #3feaea, #0168e6);
  237. }
  238. .tip-link {
  239. position: fixed;
  240. letter-spacing: 4rpx;
  241. bottom: 50rpx;
  242. left: 40rpx;
  243. font-size: 28rpx;
  244. color: #a1a2a3;
  245. text {
  246. padding-left: 10rpx;
  247. color: #226ef0;
  248. }
  249. }
  250. }
  251. .captchainput {
  252. width: 300rpx;
  253. }
  254. </style>