login.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <template>
  2. <view class="content">
  3. <view class="info_bg">
  4. <image src="../../static/management/login-bg.png" class="bgImg"></image>
  5. <div class="title">
  6. <image src="../../static/management/logo.svg"></image>
  7. <text>双碳感知资产运营管理平台</text>
  8. </div>
  9. </view>
  10. <view class="form-box">
  11. <view class="loginTxt">登录</view>
  12. <view class="row-input">
  13. <u-icon
  14. name="account"
  15. color="#2979ff"
  16. size="50"
  17. style="padding: 0 20rpx"
  18. ></u-icon>
  19. <input
  20. v-model="account"
  21. placeholder="请输入用户账号"
  22. maxlength="18"
  23. clearable
  24. />
  25. </view>
  26. <view class="row-input">
  27. <u-icon
  28. name="lock"
  29. color="#2979ff"
  30. size="50"
  31. style="padding: 0 20rpx"
  32. ></u-icon>
  33. <input
  34. v-model="password"
  35. placeholder="登陆密码"
  36. clearable
  37. :password="!isShowPassword"
  38. />
  39. <u-icon
  40. name="eye-fill"
  41. color="#2979ff"
  42. size="50"
  43. style="padding-right: 20rpx"
  44. v-if="isShowPassword"
  45. @click="showOrHide"
  46. ></u-icon>
  47. <u-icon
  48. name="eye-off"
  49. color="#2979ff"
  50. size="50"
  51. style="padding-right: 0rpx"
  52. v-else
  53. @click="showOrHide"
  54. >
  55. </u-icon>
  56. </view>
  57. <view class="Userprotocols">
  58. <view class="Userprotocolchecked">
  59. <checkbox :checked="rememberPsw" @click="checkboxChange" />
  60. </view>
  61. <view class="Userprotocoltext">记住账号密码</view>
  62. </view>
  63. <view class="Userprotocol">
  64. <view class="Userprotocolchecked">
  65. <checkbox
  66. :checked="isChecked"
  67. @click="isChecked = !isChecked"
  68. style="transform: scale(0.7)"
  69. ></checkbox>
  70. </view>
  71. <view class="Userprotocoltext">我已阅读并同意 <span @click="useragement">用户协议</span> 和 <span @click="Userprotocol">隐私政策</span> </view
  72. >
  73. </view>
  74. <view class="login-btn" @click="loginbtn">登录</view>
  75. </view>
  76. <u-toast ref="uToast" />
  77. </view>
  78. </template>
  79. <script>
  80. export default {
  81. data() {
  82. return {
  83. isChecked: true,
  84. rememberPsw:true,
  85. isShowPassword: false,
  86. account: "",
  87. password: "",
  88. captcha: "",
  89. uuid: "",
  90. captchaPath: "",
  91. };
  92. },
  93. onLoad() {
  94. // this.getCaptcha();
  95. //this.getDeviceInfo();
  96. //this.getOAID();
  97. },
  98. onUnload() {
  99. //触发水印显示
  100. uni.$emit("ly-show-watermark");
  101. },
  102. mounted() {//记住密码
  103. //缓存的账号
  104. const HBusername = uni.getStorageSync('HBusername');
  105. //缓存的密码
  106. const HBpassword = uni.getStorageSync('HBpassword');
  107. //console.log("缓存的账号:"+HBusername)
  108. //console.log("缓存的密码:"+HBpassword)
  109. //有缓存就赋值给文本没有就清空
  110. if (HBusername && HBpassword) {
  111. this.account = HBusername;
  112. this.password = HBpassword;
  113. } else {
  114. this.account = '';
  115. this.password = '';
  116. }
  117. //自动登录
  118. },
  119. methods: {
  120. getDeviceInfo(){
  121. plus.device.getInfo({
  122. success:function(e){
  123. console.log('getDeviceInfo success: '+JSON.stringify(e));
  124. },
  125. fail:function(e){
  126. console.log('getDeviceInfo failed: '+JSON.stringify(e));
  127. }
  128. });
  129. },
  130. getOAID(){
  131. plus.device.getOAID({
  132. success:function(e){
  133. console.log('getOAID success: '+JSON.stringify(e));
  134. },
  135. fail:function(e){
  136. console.log('getOAID failed: '+JSON.stringify(e));
  137. }
  138. });
  139. },
  140. //复选框
  141. checkboxChange: function(e) {
  142. this.rememberPsw=!this.rememberPsw;
  143. console.log('111111111111111111',this.rememberPsw)
  144. if (this.rememberPsw == true) {
  145. //获取缓存的账号 赋值
  146. uni.getStorageSync('HBusername',this.account);
  147. uni.getStorageSync('HBpassword',this.password);
  148. } else {//销毁
  149. uni.removeStorageSync('HBusername');
  150. uni.removeStorageSync('HBpassword');
  151. }
  152. },
  153. loginbtn() {
  154. if (this.account == "") {
  155. this.$refs.uToast.show({
  156. type: "error",
  157. message: "请输入账号",
  158. });
  159. return false
  160. } else if (this.password == "") {
  161. this.$refs.uToast.show({
  162. type: "error",
  163. message: "请同意用户协议和隐私政策",
  164. });
  165. return false
  166. }
  167. let formData = {
  168. username: this.account,
  169. password: this.password,
  170. };
  171. //登录功能
  172. this.$api.post("/login", formData).then((res) => {
  173. if (res.data.code == 0) {
  174. uni.setStorageSync("tokendata", res.data.data.token); //token
  175. uni.setStorageSync("Userinformation", formData); //用户信息
  176. //获取用户的信息,如组织架构,个人信息,权限等
  177. Promise.all([
  178. this.getpermissions(),
  179. this.getDictList(),
  180. this.getuserInfo(),
  181. ]).then(() => {
  182. uni.navigateTo({
  183. url: "/pages/index/index",
  184. });
  185. });
  186. return false
  187. } else if (this.password == "") {
  188. this.$refs.uToast.show({
  189. type: "error",
  190. message: "请输入密码",
  191. });
  192. return false
  193. }
  194. let formData = {
  195. username: this.account,
  196. password: this.password,
  197. };
  198. //登录功能
  199. this.$api.post("/login", formData).then((res) => {
  200. if (res.data.code == 0) {
  201. uni.setStorageSync("tokendata", res.data.data.token); //token
  202. uni.setStorageSync("Userinformation", formData); //用户信息
  203. //勾选就缓存账号和密码
  204. if (this.rememberPsw) {
  205. uni.setStorageSync('HBusername', this.account);
  206. uni.setStorageSync('HBpassword', this.password);
  207. } else {//销毁缓存
  208. uni.removeStorageSync('HBusername');
  209. uni.removeStorageSync('HBpassword');
  210. }
  211. //获取用户的信息,如组织架构,个人信息,权限等
  212. Promise.all([
  213. this.getpermissions(),
  214. this.getDictList(),
  215. this.getuserInfo(),
  216. ]).then(() => {
  217. uni.navigateTo({
  218. url: "/pages/index/index",
  219. });
  220. });
  221. } else {
  222. this.$refs.uToast.show({
  223. type: "error",
  224. message: "账号或者密码错误,请重新输入",
  225. });
  226. }
  227. });
  228. })
  229. },
  230. getpermissions() {
  231. //获取用户权限功能
  232. return new Promise((resolve, reject) => {
  233. this.$api
  234. .get("/menu/permissions", {})
  235. .then((res) => {
  236. uni.setStorageSync("ButtonPermissions", res.data.data);
  237. resolve(res);
  238. })
  239. .catch((e) => {
  240. reject(e);
  241. });
  242. });
  243. },
  244. getDictList() {
  245. //获取字典列表, 添加并全局变量保存
  246. return new Promise((resolve, reject) => {
  247. this.$api
  248. .get("/all", {})
  249. .then((res) => {
  250. uni.setStorageSync("getDictDataList", res.data.data);
  251. resolve(res);
  252. // console.log('222222', res)
  253. })
  254. .catch((e) => {
  255. reject(e);
  256. });
  257. });
  258. },
  259. getuserInfo() {
  260. //获取用户信息
  261. return new Promise((resolve, reject) => {
  262. this.$api
  263. .get("/user/userInfo", {})
  264. .then((res) => {
  265. uni.setStorageSync("getuserInfo", res.data.data);
  266. resolve(res);
  267. })
  268. .catch((e) => {
  269. reject(e);
  270. });
  271. });
  272. },
  273. // 密码显示/密码隐藏
  274. showOrHide() {
  275. this.isShowPassword = !this.isShowPassword;
  276. },
  277. Userprotocol() {
  278. uni.navigateTo({
  279. url: "/pages/login/Privacyagreement",
  280. success: (res) => {},
  281. fail: () => {},
  282. complete: () => {},
  283. });
  284. },
  285. useragement(){
  286. uni.navigateTo({
  287. url: "/pages/login/useragree",
  288. success: (res) => {},
  289. fail: () => {},
  290. complete: () => {},
  291. });
  292. },
  293. // 找回密码
  294. forget() {
  295. uni.navigateTo({
  296. url: "/pages/login/forget",
  297. success: (res) => {},
  298. fail: () => {},
  299. complete: () => {},
  300. });
  301. },
  302. // 注册
  303. register() {
  304. uni.navigateTo({
  305. url: "/pages/login/register",
  306. success: (res) => {},
  307. fail: () => {},
  308. complete: () => {},
  309. });
  310. },
  311. },
  312. };
  313. </script>
  314. <style lang="scss">
  315. .Userprotocol{
  316. margin-top: 60rpx;
  317. display: flex;
  318. align-items: center;
  319. justify-content: flex-end;
  320. font-size: 12px;
  321. }
  322. .Userprotocols{
  323. margin-top: -30rpx;
  324. margin-right:-70rpx;
  325. display: flex;
  326. align-items: center;
  327. justify-content: flex-end;
  328. transform: scale(.75);
  329. }
  330. .Userprotocoltext{
  331. color: #5C8FFF;
  332. span{
  333. color: #a1a2a3;
  334. }
  335. }
  336. .form-box {
  337. width: 91%;
  338. background: #fff;
  339. margin: -148rpx auto 0;
  340. position: relative;
  341. z-index: 3;
  342. padding: 60rpx 40rpx 100rpx;
  343. box-sizing: border-box;
  344. border-radius: 32rpx;
  345. .loginTxt {
  346. color: #0c1935;
  347. font-size: 40rpx;
  348. margin-bottom: 80rpx;
  349. text-align: center;
  350. }
  351. .row-input {
  352. display: flex;
  353. align-items: center;
  354. height: 80rpx;
  355. background-color: #f4f7ff;
  356. border-radius: 36rpx;
  357. margin-bottom: 40rpx;
  358. padding: 0 20rpx;
  359. input {
  360. width: 460rpx;
  361. font-size: 30rpx;
  362. color: #a1a2a3;
  363. flex: 1;
  364. }
  365. }
  366. .Userprotocol{
  367. display: flex;
  368. align-items: center;
  369. justify-content: center;
  370. margin-top: 140rpx;
  371. }
  372. .login-btn {
  373. margin-top: 20rpx;
  374. font-size: 16px;
  375. letter-spacing: 7px;
  376. color: #ffffff;
  377. height: 40px;
  378. border-radius: 18px;
  379. background: #5c8fff;
  380. text-align: center;
  381. line-height: 40px;
  382. }
  383. }
  384. .content {
  385. .bgImg {
  386. width: 78%;
  387. position: absolute;
  388. left: -5px;
  389. top: 9px;
  390. z-index: 0;
  391. }
  392. .title {
  393. display: flex;
  394. align-items: center;
  395. justify-content: center;
  396. position: relative;
  397. z-index: 2;
  398. image {
  399. width: 64rpx;
  400. height: 64rpx;
  401. margin-right: 4rpx;
  402. }
  403. text {
  404. font-size: 36rpx;
  405. color: #fff;
  406. }
  407. }
  408. }
  409. .info_bg {
  410. padding-top: 60rpx;
  411. width: 100%;
  412. height: 400rpx;
  413. background: #5c8fff;
  414. border-radius: 0px 0px 32rpx 32rpx;
  415. position: relative;
  416. image {
  417. width: 272px;
  418. height: 157px;
  419. }
  420. }
  421. </style>