login.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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" style="transform: scale(0.7);"></checkbox>
  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. return false
  63. } else if (this.password == "") {
  64. this.$refs.uToast.show({
  65. type: "error",
  66. message: "请输入密码",
  67. });
  68. return false
  69. }
  70. let formData = {
  71. username: this.account,
  72. password: this.password,
  73. };
  74. //登录功能
  75. this.$api.post("/login", formData).then((res) => {
  76. if (res.data.code == 0) {
  77. uni.setStorageSync("tokendata", res.data.data.token); //token
  78. uni.setStorageSync("Userinformation", formData); //用户信息
  79. //获取用户的信息,如组织架构,个人信息,权限等
  80. Promise.all([
  81. this.getpermissions(),
  82. this.getDictList(),
  83. this.getuserInfo(),
  84. ]).then(() => {
  85. uni.navigateTo({
  86. url: "/pages/index/index",
  87. });
  88. });
  89. } else {
  90. this.$refs.uToast.show({
  91. type: "error",
  92. message: "账号或者密码错误,请重新输入",
  93. });
  94. }
  95. });
  96. },
  97. getpermissions() {
  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: -148rpx 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. .Userprotocol{
  205. display: flex;
  206. align-items: center;
  207. justify-content: center;
  208. margin-top: 100rpx;
  209. }
  210. .login-btn {
  211. margin-top: 20rpx;
  212. font-size: 16px;
  213. letter-spacing: 7px;
  214. color: #ffffff;
  215. height: 40px;
  216. border-radius: 18px;
  217. background: #5c8fff;
  218. text-align: center;
  219. line-height: 40px;
  220. }
  221. }
  222. .content {
  223. .bgImg {
  224. width: 78%;
  225. position: absolute;
  226. left: -5px;
  227. top: 9px;
  228. z-index: 0;
  229. }
  230. .title {
  231. display: flex;
  232. align-items: center;
  233. justify-content: center;
  234. position: relative;
  235. z-index: 2;
  236. image {
  237. width: 64rpx;
  238. height: 64rpx;
  239. margin-right: 4rpx;
  240. }
  241. text {
  242. font-size: 36rpx;
  243. color: #fff;
  244. }
  245. }
  246. }
  247. .info_bg {
  248. padding-top: 60rpx;
  249. width: 100%;
  250. height: 400rpx;
  251. background: #5c8fff;
  252. border-radius: 0px 0px 32rpx 32rpx;
  253. position: relative;
  254. image {
  255. width: 272px;
  256. height: 157px;
  257. }
  258. }
  259. </style>