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