login.vue 8.7 KB

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