login.vue 9.7 KB

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