login.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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="Userprotocol">
  25. <view class="Userprotocolchecked">
  26. <checkbox :checked="isChecked" @click="isChecked=!isChecked" />
  27. </view>
  28. <view class="Userprotocoltext" @click="Userprotocol">我已阅读并同意用户协议和隐私政策</view>
  29. </view>
  30. </view>
  31. <view class="login-btn" @click="loginbtn">登录</view>
  32. </view>
  33. <u-toast ref="uToast" />
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. isChecked: true,
  41. isShowPassword: false,
  42. account: "",
  43. password: "",
  44. captcha: "",
  45. uuid: "",
  46. captchaPath: "",
  47. };
  48. },
  49. onLoad() {
  50. // this.getCaptcha();
  51. },
  52. onUnload() {
  53. //触发水印显示
  54. uni.$emit("ly-show-watermark");
  55. },
  56. methods: {
  57. loginbtn() {
  58. if (this.account == "") {
  59. this.$refs.uToast.show({
  60. type: "error",
  61. message: "请输入账号",
  62. });
  63. } else if (this.password == "") {
  64. this.$refs.uToast.show({
  65. type: "error",
  66. message: "请输入密码",
  67. });
  68. }
  69. let formData = {
  70. username: this.account,
  71. password: this.password,
  72. };
  73. //登录功能
  74. this.$api.post("/login", formData).then((res) => {
  75. if (res.data.code == 0) {
  76. uni.setStorageSync("tokendata", res.data.data.token); //token
  77. uni.setStorageSync("Userinformation", formData); //用户信息
  78. //获取用户的信息,如组织架构,个人信息,权限等
  79. Promise.all([
  80. this.getpermissions(),
  81. this.getDictList(),
  82. this.getuserInfo(),
  83. ]).then(() => {
  84. uni.navigateTo({
  85. url: "/pages/index/index",
  86. });
  87. });
  88. } else {
  89. this.$refs.uToast.show({
  90. type: "error",
  91. message: "账号或者密码错误,请重新输入",
  92. });
  93. }
  94. });
  95. },
  96. getpermissions() {
  97. console.log("权限功能");
  98. //获取用户权限功能
  99. return new Promise((resolve, reject) => {
  100. this.$api
  101. .get("/menu/permissions", {})
  102. .then((res) => {
  103. uni.setStorageSync("ButtonPermissions", res.data.data);
  104. resolve(res);
  105. })
  106. .catch((e) => {
  107. reject(e);
  108. });
  109. });
  110. },
  111. getDictList() {
  112. //获取字典列表, 添加并全局变量保存
  113. return new Promise((resolve, reject) => {
  114. this.$api
  115. .get("/all", {})
  116. .then((res) => {
  117. uni.setStorageSync("getDictDataList", res.data.data);
  118. resolve(res);
  119. // console.log('222222', res)
  120. })
  121. .catch((e) => {
  122. reject(e);
  123. });
  124. });
  125. },
  126. getuserInfo() {
  127. //获取用户信息
  128. return new Promise((resolve, reject) => {
  129. this.$api
  130. .get("/user/userInfo", {})
  131. .then((res) => {
  132. uni.setStorageSync("getuserInfo", res.data.data);
  133. resolve(res);
  134. })
  135. .catch((e) => {
  136. reject(e);
  137. });
  138. });
  139. },
  140. // 密码显示/密码隐藏
  141. showOrHide() {
  142. this.isShowPassword = !this.isShowPassword;
  143. },
  144. Userprotocol() {
  145. uni.navigateTo({
  146. url: "/pages/login/Privacyagreement",
  147. success: (res) => {},
  148. fail: () => {},
  149. complete: () => {},
  150. });
  151. },
  152. // 找回密码
  153. forget() {
  154. uni.navigateTo({
  155. url: "/pages/login/forget",
  156. success: (res) => {},
  157. fail: () => {},
  158. complete: () => {},
  159. });
  160. },
  161. // 注册
  162. register() {
  163. uni.navigateTo({
  164. url: "/pages/login/register",
  165. success: (res) => {},
  166. fail: () => {},
  167. complete: () => {},
  168. });
  169. },
  170. },
  171. };
  172. </script>
  173. <style lang="scss">
  174. .form-box {
  175. width: 91%;
  176. background: #fff;
  177. margin: -130rpx auto 0;
  178. position: relative;
  179. z-index: 3;
  180. padding: 60rpx 40rpx 100rpx;
  181. box-sizing: border-box;
  182. border-radius: 32rpx;
  183. .loginTxt {
  184. color: #0c1935;
  185. font-size: 40rpx;
  186. margin-bottom: 80rpx;
  187. text-align: center;
  188. }
  189. .row-input {
  190. display: flex;
  191. align-items: center;
  192. height: 80rpx;
  193. background-color: #f4f7ff;
  194. border-radius: 36rpx;
  195. margin-bottom: 40rpx;
  196. padding: 0 20rpx;
  197. input {
  198. width: 460rpx;
  199. font-size: 30rpx;
  200. color: #a1a2a3;
  201. flex: 1;
  202. }
  203. }
  204. .login-btn {
  205. margin-top: 50px;
  206. font-size: 16px;
  207. letter-spacing: 7px;
  208. color: #ffffff;
  209. height: 40px;
  210. border-radius: 18px;
  211. background: #5c8fff;
  212. text-align: center;
  213. line-height: 40px;
  214. }
  215. }
  216. .content {
  217. .bgImg {
  218. width: 78%;
  219. position: absolute;
  220. left: -5px;
  221. top: 9px;
  222. z-index: 0;
  223. }
  224. .title {
  225. display: flex;
  226. align-items: center;
  227. justify-content: center;
  228. position: relative;
  229. z-index: 2;
  230. image {
  231. width: 64rpx;
  232. height: 64rpx;
  233. margin-right: 4rpx;
  234. }
  235. text {
  236. font-size: 36rpx;
  237. color: #fff;
  238. }
  239. }
  240. }
  241. .info_bg {
  242. padding-top: 40rpx;
  243. width: 100%;
  244. height: 400rpx;
  245. background: #5c8fff;
  246. border-radius: 0px 0px 32rpx 32rpx;
  247. position: relative;
  248. image {
  249. width: 272px;
  250. height: 157px;
  251. }
  252. }
  253. </style>