login.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <template>
  2. <div class="login">
  3. <img src="../../common/assets/image/logobig.png" alt="" class="logobig" />
  4. <img src="./topimg.png" alt="" class="topimg" />
  5. <div class="wellogin">
  6. <div class="loginBox">
  7. <div class="logTit">
  8. <span class="titletxt">欢迎登录</span>
  9. </div>
  10. <div class="inputBox">
  11. <img src="../../common/assets/image/comicon.png" alt="" />
  12. <input
  13. type="text"
  14. placeholder="请输入账号"
  15. v-model="loginForm.userName"
  16. />
  17. </div>
  18. <div class="inputBox">
  19. <img src="../../common/assets/image/pswicon.svg" alt="" />
  20. <input
  21. v-if="isPassWord"
  22. :password="true"
  23. placeholder="请输入密码"
  24. v-model="loginForm.password"
  25. style="border-right: none"
  26. />
  27. <input
  28. v-if="!isPassWord"
  29. :password="false"
  30. placeholder="请输入密码"
  31. style="border-right: none"
  32. v-model="loginForm.password"
  33. />
  34. <div style="background: #f3f5f9;height: 100rpx;line-height: 100rpx;padding: 4rpx 0;border: 1rpx solid rgba(29, 24, 188, 0.05);border-left: none;padding-left: 20rpx; padding-right: 20rpx;" @click="changeIsPassWord()" >
  35. <van-icon name="eye-o" v-if="isPassWord" />
  36. <van-icon name="closed-eye" v-if="!isPassWord"/>
  37. </div>
  38. </div>
  39. <div class="inputBox">
  40. <img src="../../common/assets/image/yzmicon.svg" alt="" />
  41. <input
  42. type="text"
  43. placeholder="验证码"
  44. class="yanzhengma"
  45. v-model="loginForm.code"
  46. />
  47. <img
  48. :src="loginForm.captchaImage"
  49. @click="captchaImageRefresh(loginForm)"
  50. class="yanzhengImg"
  51. />
  52. </div>
  53. <div class="inputBox" style=" justify-content: flex-end;">
  54. <van-checkbox checked-color="#8a0554" :value="isSetPassWord" @change=changeIsSetPassWord() bind:change="onChange">记住密码</van-checkbox>
  55. </div>
  56. <div style="margin-top: 2vh">
  57. <van-button
  58. type="default"
  59. class="loginbtn"
  60. size="large"
  61. color="rgba(138, 5, 84, 1)"
  62. @click="login"
  63. >登 录</van-button
  64. >
  65. </div>
  66. </div>
  67. </div>
  68. <div class="bottomTips">
  69. <van-checkbox :value="isCheck" @change="getIsCheck" checked-color="#8a0554" />
  70. 已阅读并同意
  71. </van-checkbox>
  72. <span style="color: #8a0554"
  73. >《服务协议条款及隐私政策》
  74. </span>
  75. </div>
  76. <van-dialog id="van-toast" />
  77. </div>
  78. </template>
  79. <script>
  80. import Dialog from "../../wxcomponents/weapp/dist/dialog/dialog.js";
  81. import { login } from "@/js_sdk/http.js";
  82. import w_md5 from "@/js_sdk/zww-md5/w_md5.js";
  83. export default {
  84. data() {
  85. return {
  86. isSetPassWord:false,
  87. isPassWord:false,
  88. isCheck:false,
  89. loginForm: {
  90. userName: "",
  91. password: "",
  92. code: "",
  93. type: "USER",
  94. captchaId: "",
  95. captchaImage: "",
  96. rememberMe: true,
  97. },
  98. };
  99. },
  100. onLoad(e) {
  101. console.log(e);
  102. // login()
  103. this.captchaImageRefresh(this.loginForm);
  104. this.loginForm.type = 'BIZ';
  105. const rememberedUser = wx.getStorageSync('rememberedUser');
  106. if (rememberedUser && rememberedUser.isSetPassWord) {
  107. // 赋值账号密码到输入框
  108. this.loginForm.userName = rememberedUser.userName;
  109. this.loginForm.password = rememberedUser.password;
  110. // 勾选"记住密码"
  111. this.isSetPassWord = true;
  112. }
  113. // this.loginForm.type = e.type ? e.type : "USER";
  114. },
  115. methods: {
  116. getIsCheck(e){
  117. console.log(e)
  118. this.isCheck=!this.isCheck
  119. },
  120. changeIsSetPassWord(){
  121. this.isSetPassWord = !this.isSetPassWord;
  122. // 未勾选时直接清除缓存
  123. if (!this.isSetPassWord) {
  124. wx.removeStorageSync('rememberedUser');
  125. }
  126. },
  127. changeIsPassWord(){
  128. this.isPassWord=!this.isPassWord
  129. console.log(123123)
  130. },
  131. async wxlogin() {
  132. let _this = this;
  133. wx.login({
  134. success: async function (res) {
  135. let data = await login({ openCode: res.code });
  136. console.log(data);
  137. _this.$auth.setUser(data.data.token);
  138. _this.$auth.setUserInfo(data.data);
  139. uni.switchTab({
  140. url: "/pages/index/index",
  141. });
  142. },
  143. });
  144. },
  145. goqy() {
  146. uni.navigateTo({
  147. url: "/pages/gocompnay/index",
  148. });
  149. },
  150. gozhfw() {
  151. wx.navigateToMiniProgram({
  152. appId: "wx9919d022c184462b",
  153. success(res) {
  154. // 打开成功
  155. },
  156. fail(e) {
  157. console.log(e);
  158. },
  159. });
  160. },
  161. captchaImageRefresh: function (_form) {
  162. _form.captchaId = this.$common.uuid(8);
  163. _form.captchaImage =
  164. this.$constant.BASE_URI +
  165. "/captcha/captchaImage?type=math&captchaId=" +
  166. _form.captchaId +
  167. "&s=" +
  168. Math.random();
  169. },
  170. forgetPsw() {
  171. wx.showModal({
  172. title: "提示!",
  173. content: "管理端修改密码需要拨打客服电话15061150110咨询,是否拨打?",
  174. success: function (res) {
  175. if (res.confirm) {
  176. uni.makePhoneCall({
  177. phoneNumber: "15061150110", //电话号码
  178. success: function (e) {},
  179. fail: function (e) {},
  180. });
  181. }
  182. },
  183. });
  184. },
  185. login() {
  186. const _this = this;
  187. if (!this.loginForm.userName || !this.loginForm.password) {
  188. uni.showModal({
  189. title: "提示",
  190. content: "请输入账号和密码",
  191. icon: "error",
  192. showCancel: false,
  193. });
  194. return;
  195. }
  196. let loginForm = {
  197. ...this.loginForm,
  198. password: w_md5.hex_md5_32(this.loginForm.password),
  199. };
  200. login(loginForm).then((res) => {
  201. if (res.errmsg == "成功") {
  202. if (_this.isSetPassWord) {
  203. // 存储账号、原始密码(未加密)、勾选状态
  204. wx.setStorageSync('rememberedUser', {
  205. userName: _this.loginForm.userName,
  206. password: _this.loginForm.password, // 存原始密码,避免重复加密
  207. isSetPassWord: true
  208. });
  209. } else {
  210. // 未勾选则清除缓存
  211. wx.removeStorageSync('rememberedUser');
  212. }
  213. uni.showToast({
  214. title: "登录成功",
  215. icon: "none",
  216. mask: true,
  217. duration: 2000,
  218. });
  219. this.$auth.setUser(res.data.token);
  220. this.$auth.setUserInfo({
  221. ...res.data,
  222. userType: this.loginForm.type,
  223. });
  224. uni.switchTab({
  225. url: "/pages/index/index",
  226. });
  227. } else {
  228. this.captchaImageRefresh(this.loginForm);
  229. }
  230. });
  231. // this.$auth.setUserType(this.$auth.TYPE_FRAME);
  232. },
  233. onShareAppMessage: function () {},
  234. },
  235. };
  236. </script>
  237. <style lang="scss">
  238. .login {
  239. background: white;
  240. height: 100%;
  241. overflow: hidden;
  242. .wellogin {
  243. width: 750rpx;
  244. height: 1060;
  245. background: #ffffff;
  246. border-radius: 40rpx 40rpx 0rpx 0rpx;
  247. position: absolute;
  248. padding-top: 68rpx;
  249. top: 330rpx;
  250. }
  251. .topimg {
  252. /* margin: auto; */
  253. display: block;
  254. margin: auto;
  255. position: absolute;
  256. left: calc(50% - 300rpx);
  257. /* width: 240rpx; */
  258. width: 600rpx;
  259. }
  260. .logTit {
  261. width: 70vw;
  262. margin-bottom: 62rpx;
  263. z-index: 1;
  264. color: rgba(51, 51, 51, 1);
  265. font-size: 4vw;
  266. p {
  267. color: rgba(102, 102, 102, 1);
  268. font-size: 4vw;
  269. margin-top: 0.5vw;
  270. }
  271. .titletxt {
  272. font-size: 48rpx;
  273. font-family: Taipei Sans TC Beta-Bold, Taipei Sans TC Beta;
  274. font-weight: bold;
  275. color: #333333;
  276. }
  277. .titletxt2 {
  278. font-size: 32rpx;
  279. font-family: PingFang SC-Regular, PingFang SC;
  280. font-weight: 400;
  281. color: #666666;
  282. }
  283. }
  284. .logobig {
  285. width: 100vw;
  286. height: 100vh;
  287. position: absolute;
  288. left: 0;
  289. z-index: 0;
  290. }
  291. .loginBox {
  292. width: 80vw;
  293. margin: auto;
  294. }
  295. .inputBox {
  296. position: relative;
  297. display: flex;
  298. align-items: center;
  299. width: 100%;
  300. img {
  301. position: absolute;
  302. width: 50rpx;
  303. height: 70rpx;
  304. margin-right: 16rpx;
  305. margin-left: 32rpx;
  306. // padding-top: 40px;
  307. }
  308. .yanzhengImg {
  309. right: 0;
  310. width: 21vw;
  311. height: 15vw;
  312. margin: 0;
  313. padding: 0;
  314. }
  315. .yanzhengImgBox {
  316. height: 50px;
  317. display: flex;
  318. align-items: center;
  319. }
  320. input {
  321. background: #f3f5f9;
  322. width: 100%;
  323. height: 100rpx;
  324. padding: 5rpx 0 5rpx 85rpx;
  325. background-color: rgba(255, 255, 255, 1);
  326. border: 1rpx solid rgba(29, 24, 188, 0.05);
  327. margin: 16rpx 0;
  328. font-size: 4vw;
  329. background: #f3f5f9;
  330. }
  331. input::-webkit-input-placeholder {
  332. color: rgba(153, 153, 153, 1);
  333. }
  334. .yanzhengma {
  335. width: 60%;
  336. }
  337. }
  338. .pswBox {
  339. width: 100%;
  340. display: flex;
  341. justify-content: flex-end;
  342. margin: 20px 0;
  343. color: rgba(29, 24, 188, 1);
  344. }
  345. .van-button {
  346. margin-top: 15rpx;
  347. border-radius: 60px;
  348. }
  349. .loginbtn {
  350. margin-top: 50rpx;
  351. }
  352. .bottomTips {
  353. width: 100vw;
  354. position: fixed;
  355. bottom: 15px;
  356. text-align: center;
  357. color: #999999;
  358. font-size: 2vw;
  359. display: flex;
  360. align-items: center;
  361. justify-content: center;
  362. }
  363. //@media screen and (max-height: 454px) {
  364. // .bottomTips {
  365. // display: none;
  366. // }
  367. //}
  368. }
  369. </style>