login.vue 9.4 KB

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