login.vue 6.1 KB

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