login.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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" clearable />
  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="登陆密码" clearable :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. <view class="Userprotocol">
  35. <view class="Userprotocolchecked">
  36. <checkbox :checked="isChecked" @click="isChecked=!isChecked" />
  37. </view>
  38. <view class="Userprotocoltext" @click="Userprotocol">
  39. 我已阅读并同意用户协议和隐私政策
  40. </view>
  41. </view>
  42. <u-toast ref="uToast" />
  43. <u-notify ref="uNotify" message="" ></u-notify>
  44. </view>
  45. </template>
  46. <script>
  47. // function getUUID() {
  48. // return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
  49. // return (c === 'x' ? (Math.random() * 16 | 0) : ('r&0x3' | '0x8')).toString(16)
  50. // })
  51. // }
  52. //const BaseApi= require("@/http/baseApi.js");
  53. export default {
  54. data() {
  55. return {
  56. isChecked:true,
  57. isShowPassword: false,
  58. account: '',
  59. password: '',
  60. captcha: '',
  61. uuid: '',
  62. captchaPath: '',
  63. }
  64. },
  65. onLoad() {
  66. // this.getCaptcha();
  67. },
  68. onUnload() {
  69. //触发水印显示
  70. uni.$emit('ly-show-watermark');
  71. },
  72. methods: {
  73. // 获取验证码
  74. // getCaptcha() {
  75. // this.uuid = getUUID();
  76. // this.captchaPath =BaseApi.BaseApi+ `/captcha?uuid=${this.uuid}`;
  77. // },
  78. loginbtn() {
  79. if(this.isChecked){
  80. if (this.account == '') {
  81. this.$refs.uToast.show({
  82. type: 'error',
  83. message: "请输入账号",
  84. })
  85. // uni.showToast({
  86. // title: "请输入账号",
  87. // icon:'error',
  88. // duration: 1000,
  89. // })
  90. } else if (this.password == '') {
  91. this.$refs.uToast.show({
  92. type: 'error',
  93. message: "请输入密码",
  94. })
  95. }
  96. let formData = {
  97. username: this.account,
  98. password: this.password,
  99. // uuid:this.uuid,
  100. // captcha:this.captcha,
  101. }
  102. //登录功能
  103. this.$api.post('/login', formData)
  104. .then(res => {
  105. if (res.data.code == 0) {
  106. uni.setStorageSync('tokendata', res.data.data.token); //token
  107. uni.setStorageSync('Userinformation', formData); //用户信息
  108. //获取用户的信息,如组织架构,个人信息,权限等
  109. Promise.all([this.getpermissions(), this.getDictList(), this.getuserInfo(), ]).then(() => {
  110. // uni.switchTab({
  111. // url: '/pages/index/index',
  112. // success: res => {},
  113. // fail: () => {},
  114. // complete: () => {},
  115. // })
  116. uni.navigateTo({
  117. url: '/pages/index/index'
  118. })
  119. });
  120. } else {
  121. this.$refs.uToast.show({
  122. type: 'error',
  123. message: "账号或者密码错误,请重新输入",
  124. })
  125. }
  126. })
  127. }else{
  128. this.$refs.uNotify.error('您尚未同意用户协议')
  129. }
  130. },
  131. getpermissions() {
  132. console.log('权限功能', )
  133. //获取用户权限功能
  134. return new Promise((resolve, reject) => {
  135. this.$api.get('/menu/permissions', {}).then((res) => {
  136. uni.setStorageSync('ButtonPermissions', res.data.data);
  137. resolve(res);
  138. // console.log('111111111111111111', res)
  139. }).catch(e => {
  140. reject(e)
  141. })
  142. });
  143. // this.$api.get('/menu/permissions', {})
  144. // .then(res1 => {
  145. // uni.setStorageSync('ButtonPermissions', res1.data.data); //权限列表
  146. // })
  147. },
  148. getDictList() {
  149. //获取字典列表, 添加并全局变量保存
  150. return new Promise((resolve, reject) => {
  151. this.$api.get('/all', {}).then((res) => {
  152. uni.setStorageSync('getDictDataList', res.data.data);
  153. resolve(res);
  154. // console.log('222222', res)
  155. }).catch(e => {
  156. reject(e)
  157. })
  158. });
  159. // this.$api.get('/all', {})
  160. // .then(res => {
  161. // // console.log('88888', res.data.data)
  162. // uni.setStorageSync('getDictDataList', res.data.data);
  163. // })
  164. },
  165. getuserInfo() {
  166. //获取用户信息
  167. return new Promise((resolve, reject) => {
  168. this.$api.get('/user/userInfo', {}).then((res) => {
  169. uni.setStorageSync('getuserInfo', res.data.data);
  170. resolve(res);
  171. //console.log('333333', res)
  172. }).catch(e => {
  173. reject(e)
  174. })
  175. });
  176. // this.$api.get('/user/userInfo', {})
  177. // .then(res => {
  178. // // console.log('88888', res.data.data)
  179. // uni.setStorageSync('getuserInfo', res.data.data);
  180. // })
  181. },
  182. // 密码显示/密码隐藏
  183. showOrHide() {
  184. this.isShowPassword = !this.isShowPassword
  185. },
  186. Userprotocol(){
  187. uni.navigateTo({
  188. url: '/pages/login/Privacyagreement',
  189. success: res => {},
  190. fail: () => {},
  191. complete: () => {},
  192. })
  193. },
  194. // 找回密码
  195. forget() {
  196. uni.navigateTo({
  197. url: '/pages/login/forget',
  198. success: res => {},
  199. fail: () => {},
  200. complete: () => {},
  201. })
  202. },
  203. // 注册
  204. register() {
  205. uni.navigateTo({
  206. url: '/pages/login/register',
  207. success: res => {},
  208. fail: () => {},
  209. complete: () => {},
  210. })
  211. }
  212. }
  213. }
  214. </script>
  215. <style lang="scss">
  216. .Userprotocol{
  217. display: flex;
  218. align-items: center;
  219. justify-content: center;
  220. position: fixed;
  221. bottom: 20rpx;
  222. left: 0rpx;
  223. right: 0rpx;
  224. }
  225. .Userprotocolchecked{
  226. }
  227. .Userprotocoltext{
  228. color: #fff;
  229. padding-left: 10rpx;
  230. }
  231. page {
  232. background-color: #0b0c14;
  233. }
  234. .content {
  235. padding: 100rpx 40rpx;
  236. }
  237. .title {
  238. display: flex;
  239. flex-direction: column;
  240. height: 200rpx;
  241. .thing {
  242. height: 8rpx;
  243. background-image: linear-gradient(to right, #3feaea, #0168e6);
  244. }
  245. .name {
  246. font-weight: bold;
  247. font-size: 50rpx;
  248. line-height: 120rpx;
  249. background: linear-gradient(to right, #3feaea, blue);
  250. background-clip: text;
  251. color: transparent;
  252. letter-spacing: 5rpx;
  253. }
  254. }
  255. .form-box {
  256. .rowinputcaptcha {
  257. display: flex;
  258. justify-content: flex-start;
  259. align-items: center;
  260. height: 110rpx;
  261. //background-color: #2b2f41;
  262. border-radius: 8rpx;
  263. margin-bottom: 50rpx;
  264. input {
  265. width: 300rpx;
  266. font-size: 30rpx;
  267. color: #a1a2a3;
  268. }
  269. }
  270. .row-input {
  271. display: flex;
  272. justify-content: flex-start;
  273. align-items: center;
  274. height: 110rpx;
  275. background-color: #2b2f41;
  276. border-radius: 8rpx;
  277. margin-bottom: 50rpx;
  278. image {
  279. margin: 0 30rpx;
  280. flex-shrink: 0;
  281. width: 38rpx;
  282. height: 38rpx;
  283. }
  284. input {
  285. width: 460rpx;
  286. font-size: 30rpx;
  287. color: #a1a2a3;
  288. }
  289. }
  290. .menu-link {
  291. display: flex;
  292. justify-content: flex-end;
  293. align-items: center;
  294. font-size: 28rpx;
  295. color: #676c7f;
  296. }
  297. .login-btn {
  298. margin-top: 60rpx;
  299. display: flex;
  300. justify-content: center;
  301. align-items: center;
  302. font-size: 35rpx;
  303. letter-spacing: 15rpx;
  304. color: #FFFFFF;
  305. height: 110rpx;
  306. border-radius: 8rpx;
  307. background-image: linear-gradient(to right, #3feaea, #0168e6);
  308. }
  309. .tip-link {
  310. position: fixed;
  311. letter-spacing: 4rpx;
  312. bottom: 50rpx;
  313. left: 40rpx;
  314. font-size: 28rpx;
  315. color: #a1a2a3;
  316. text {
  317. padding-left: 10rpx;
  318. color: #226ef0;
  319. }
  320. }
  321. }
  322. .captchainput {
  323. width: 300rpx;
  324. }
  325. </style>