login.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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. //this.getDeviceInfo();
  58. //this.getOAID();
  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. //console.log("缓存的密码:"+HBpassword)
  71. //有缓存就赋值给文本没有就清空
  72. if (HBusername && HBpassword) {
  73. this.account = HBusername;
  74. this.password = HBpassword;
  75. } else {
  76. this.account = '';
  77. this.password = '';
  78. }
  79. //自动登录
  80. },
  81. methods: {
  82. getDeviceInfo(){
  83. plus.device.getInfo({
  84. success:function(e){
  85. console.log('getDeviceInfo success: '+JSON.stringify(e));
  86. },
  87. fail:function(e){
  88. console.log('getDeviceInfo failed: '+JSON.stringify(e));
  89. }
  90. });
  91. },
  92. getOAID(){
  93. plus.device.getOAID({
  94. success:function(e){
  95. console.log('getOAID success: '+JSON.stringify(e));
  96. },
  97. fail:function(e){
  98. console.log('getOAID failed: '+JSON.stringify(e));
  99. }
  100. });
  101. },
  102. //复选框
  103. checkboxChange: function(e) {
  104. this.rememberPsw=!this.rememberPsw;
  105. console.log('111111111111111111',this.rememberPsw)
  106. if (this.rememberPsw == true) {
  107. //获取缓存的账号 赋值
  108. uni.getStorageSync('HBusername',this.account);
  109. uni.getStorageSync('HBpassword',this.password);
  110. } else {//销毁
  111. uni.removeStorageSync('HBusername');
  112. uni.removeStorageSync('HBpassword');
  113. }
  114. },
  115. loginbtn() {
  116. if(this.isChecked==false){
  117. this.$refs.uToast.show({
  118. type: "error",
  119. message: "请同意用户协议和隐私政策",
  120. });
  121. }else{
  122. if (this.account == "") {
  123. this.$refs.uToast.show({
  124. type: "error",
  125. message: "请输入账号",
  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. console.log("权限功能");
  173. //获取用户权限功能
  174. return new Promise((resolve, reject) => {
  175. this.$api
  176. .get("/menu/permissions", {})
  177. .then((res) => {
  178. uni.setStorageSync("ButtonPermissions", res.data.data);
  179. resolve(res);
  180. })
  181. .catch((e) => {
  182. reject(e);
  183. });
  184. });
  185. },
  186. getDictList() {
  187. //获取字典列表, 添加并全局变量保存
  188. return new Promise((resolve, reject) => {
  189. this.$api
  190. .get("/all", {})
  191. .then((res) => {
  192. uni.setStorageSync("getDictDataList", res.data.data);
  193. resolve(res);
  194. // console.log('222222', res)
  195. })
  196. .catch((e) => {
  197. reject(e);
  198. });
  199. });
  200. },
  201. getuserInfo() {
  202. //获取用户信息
  203. return new Promise((resolve, reject) => {
  204. this.$api
  205. .get("/user/userInfo", {})
  206. .then((res) => {
  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. // 找回密码
  228. forget() {
  229. uni.navigateTo({
  230. url: "/pages/login/forget",
  231. success: (res) => {},
  232. fail: () => {},
  233. complete: () => {},
  234. });
  235. },
  236. // 注册
  237. register() {
  238. uni.navigateTo({
  239. url: "/pages/login/register",
  240. success: (res) => {},
  241. fail: () => {},
  242. complete: () => {},
  243. });
  244. },
  245. },
  246. };
  247. </script>
  248. <style lang="scss">
  249. .Userprotocol{
  250. margin-top: 60rpx;
  251. display: flex;
  252. align-items: center;
  253. justify-content: flex-start;
  254. }
  255. .Userprotocols{
  256. margin-top: 30rpx;
  257. display: flex;
  258. align-items: center;
  259. justify-content: flex-start;
  260. }
  261. .Userprotocoltext{
  262. color: #5C8FFF;
  263. }
  264. .form-box {
  265. width: 91%;
  266. background: #fff;
  267. margin: -130rpx auto 0;
  268. position: relative;
  269. z-index: 3;
  270. padding: 60rpx 40rpx 100rpx;
  271. box-sizing: border-box;
  272. border-radius: 32rpx;
  273. .loginTxt {
  274. color: #0c1935;
  275. font-size: 40rpx;
  276. margin-bottom: 80rpx;
  277. text-align: center;
  278. }
  279. .row-input {
  280. display: flex;
  281. align-items: center;
  282. height: 80rpx;
  283. background-color: #f4f7ff;
  284. border-radius: 36rpx;
  285. margin-bottom: 40rpx;
  286. padding: 0 20rpx;
  287. input {
  288. width: 460rpx;
  289. font-size: 30rpx;
  290. color: #a1a2a3;
  291. flex: 1;
  292. }
  293. }
  294. .login-btn {
  295. margin-top: 20px;
  296. font-size: 16px;
  297. letter-spacing: 7px;
  298. color: #ffffff;
  299. height: 40px;
  300. border-radius: 18px;
  301. background: #5c8fff;
  302. text-align: center;
  303. line-height: 40px;
  304. }
  305. }
  306. .content {
  307. .bgImg {
  308. width: 78%;
  309. position: absolute;
  310. left: -5px;
  311. top: 9px;
  312. z-index: 0;
  313. }
  314. .title {
  315. display: flex;
  316. align-items: center;
  317. justify-content: center;
  318. position: relative;
  319. z-index: 2;
  320. image {
  321. width: 64rpx;
  322. height: 64rpx;
  323. margin-right: 4rpx;
  324. }
  325. text {
  326. font-size: 36rpx;
  327. color: #fff;
  328. }
  329. }
  330. }
  331. .info_bg {
  332. padding-top: 40rpx;
  333. width: 100%;
  334. height: 400rpx;
  335. background: #5c8fff;
  336. border-radius: 0px 0px 32rpx 32rpx;
  337. position: relative;
  338. image {
  339. width: 272px;
  340. height: 157px;
  341. }
  342. }
  343. </style>