login.vue 7.9 KB

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