login.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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: 'admin',
  49. password: 'cx868688',
  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. return new Promise((resolve, reject) => {
  114. this.$api.get('/menu/permissions', {}).then((res) => {
  115. uni.setStorageSync('ButtonPermissions', res.data.data);
  116. resolve(res);
  117. console.log('111111111111111111', res)
  118. }).catch(e => {
  119. reject(e)
  120. })
  121. });
  122. // this.$api.get('/menu/permissions', {})
  123. // .then(res1 => {
  124. // uni.setStorageSync('ButtonPermissions', res1.data.data); //权限列表
  125. // })
  126. },
  127. getDictList() {
  128. //获取字典列表, 添加并全局变量保存
  129. return new Promise((resolve, reject) => {
  130. this.$api.get('/all', {}).then((res) => {
  131. uni.setStorageSync('getDictDataList', res.data.data);
  132. resolve(res);
  133. console.log('222222', res)
  134. }).catch(e => {
  135. reject(e)
  136. })
  137. });
  138. // this.$api.get('/all', {})
  139. // .then(res => {
  140. // // console.log('88888', res.data.data)
  141. // uni.setStorageSync('getDictDataList', res.data.data);
  142. // })
  143. },
  144. getuserInfo() {
  145. //获取用户信息
  146. return new Promise((resolve, reject) => {
  147. this.$api.get('/user/userInfo', {}).then((res) => {
  148. uni.setStorageSync('getuserInfo', res.data.data);
  149. resolve(res);
  150. console.log('333333', res)
  151. }).catch(e => {
  152. reject(e)
  153. })
  154. });
  155. // this.$api.get('/user/userInfo', {})
  156. // .then(res => {
  157. // // console.log('88888', res.data.data)
  158. // uni.setStorageSync('getuserInfo', res.data.data);
  159. // })
  160. },
  161. // 密码显示/密码隐藏
  162. showOrHide() {
  163. this.isShowPassword = !this.isShowPassword
  164. },
  165. // 找回密码
  166. forget() {
  167. uni.navigateTo({
  168. url: '/pages/login/forget',
  169. success: res => {},
  170. fail: () => {},
  171. complete: () => {},
  172. })
  173. },
  174. // 注册
  175. register() {
  176. uni.navigateTo({
  177. url: '/pages/login/register',
  178. success: res => {},
  179. fail: () => {},
  180. complete: () => {},
  181. })
  182. }
  183. }
  184. }
  185. </script>
  186. <style lang="scss">
  187. page {
  188. background-color: #0b0c14;
  189. }
  190. .content {
  191. padding: 100rpx 40rpx;
  192. }
  193. .title {
  194. display: flex;
  195. flex-direction: column;
  196. height: 200rpx;
  197. .thing {
  198. height: 8rpx;
  199. background-image: linear-gradient(to right, #3feaea, #0168e6);
  200. }
  201. .name {
  202. font-weight: bold;
  203. font-size: 50rpx;
  204. line-height: 120rpx;
  205. background: linear-gradient(to right, #3feaea, blue);
  206. background-clip: text;
  207. color: transparent;
  208. letter-spacing: 5rpx;
  209. }
  210. }
  211. .form-box {
  212. .rowinputcaptcha {
  213. display: flex;
  214. justify-content: flex-start;
  215. align-items: center;
  216. height: 110rpx;
  217. //background-color: #2b2f41;
  218. border-radius: 8rpx;
  219. margin-bottom: 50rpx;
  220. input {
  221. width: 300rpx;
  222. font-size: 30rpx;
  223. color: #a1a2a3;
  224. }
  225. }
  226. .row-input {
  227. display: flex;
  228. justify-content: flex-start;
  229. align-items: center;
  230. height: 110rpx;
  231. background-color: #2b2f41;
  232. border-radius: 8rpx;
  233. margin-bottom: 50rpx;
  234. image {
  235. margin: 0 30rpx;
  236. flex-shrink: 0;
  237. width: 38rpx;
  238. height: 38rpx;
  239. }
  240. input {
  241. width: 460rpx;
  242. font-size: 30rpx;
  243. color: #a1a2a3;
  244. }
  245. }
  246. .menu-link {
  247. display: flex;
  248. justify-content: flex-end;
  249. align-items: center;
  250. font-size: 28rpx;
  251. color: #676c7f;
  252. }
  253. .login-btn {
  254. margin-top: 60rpx;
  255. display: flex;
  256. justify-content: center;
  257. align-items: center;
  258. font-size: 35rpx;
  259. letter-spacing: 15rpx;
  260. color: #FFFFFF;
  261. height: 110rpx;
  262. border-radius: 8rpx;
  263. background-image: linear-gradient(to right, #3feaea, #0168e6);
  264. }
  265. .tip-link {
  266. position: fixed;
  267. letter-spacing: 4rpx;
  268. bottom: 50rpx;
  269. left: 40rpx;
  270. font-size: 28rpx;
  271. color: #a1a2a3;
  272. text {
  273. padding-left: 10rpx;
  274. color: #226ef0;
  275. }
  276. }
  277. }
  278. .captchainput {
  279. width: 300rpx;
  280. }
  281. </style>