login.vue 9.6 KB

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