login.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <div style="background-color: #F6F6F6;">
  3. <view class="zai-box">
  4. <scroll-view scroll-y class="page">
  5. <view style="text-align: center;">
  6. <image src="/static/icon/gklog.jpeg" mode='aspectFit' class="zai-logo"></image>
  7. </view>
  8. <view class="zai-title"></view>
  9. <view class="box padding-lr-xl login-paddingtop" :style="[{animation: 'show ' + 0.6+ 's 1'}]">
  10. <view class="cu-form-group margin-top round shadow-blur">
  11. <view class="title">账号:</view>
  12. <input placeholder="请输入账号" name="input" v-model="userName"></input>
  13. </view>
  14. <view class="cu-form-group margin-top round">
  15. <view class="title">密码:</view>
  16. <input placeholder="请输入密码" name="input" type="password" v-model="password"></input>
  17. </view>
  18. <div style="height: 10px;"></div>
  19. <view>
  20. <checkbox-group @change="checkboxChange">
  21. <ul>
  22. <li>
  23. <label>
  24. <checkbox :value="checkbox[0].value" :class="checkbox[0].checked=='true'?'checked':''"
  25. :checked="checkbox[0].checked=='true'?true:false" style="transform:scale(0.7)" />
  26. 记住密码
  27. </label>
  28. </li>
  29. </ul>
  30. </checkbox-group>
  31. </view>
  32. <view class="padding flex flex-direction">
  33. <button class="cu-btn bg-green shadow-blur round lg" :loading="loading" @tap="onLogin">
  34. {{loading ? "登录中...":"登 录"}}
  35. </button>
  36. </view>
  37. </view>
  38. </scroll-view>
  39. <!-- 登录加载弹窗 -->
  40. <view class="cu-load load-modal" v-if="loading">
  41. <image src="/static/login3.png" mode="aspectFit" style="top: 35px;"></image>
  42. <view class="gray-text" style="margin-top: 35px;">登录中...</view>
  43. </view>
  44. </view>
  45. </div>
  46. </template>
  47. <script>
  48. import {
  49. ACCESS_TOKEN,
  50. USER_NAME,
  51. USER_INFO
  52. } from "@/common/util/constants"
  53. import {
  54. mapActions
  55. } from "vuex"
  56. import myImageUpload from "@/components/my-componets/my-image-upload.vue"
  57. import mypage from "@/components/my-componets/my-page.vue"
  58. import myselect from "@/components/my-componets/my-select.vue"
  59. export default {
  60. components: {
  61. 'my-image-upload': myImageUpload,
  62. 'my-select': myselect
  63. },
  64. data() {
  65. return {
  66. loading: false,
  67. exitloading:false,
  68. userName: '',
  69. value: 1,
  70. password: '',
  71. phoneNo: '',
  72. smsCode: '',
  73. showPassword: false, //是否显示明文
  74. loginWay: 1, //1: 账密,2:验证码
  75. smsCountDown: 0,
  76. smsCountInterval: null,
  77. toggleDelay: false,
  78. version: '',
  79. timeoutid:null,
  80. checkbox: [{
  81. value: '1',
  82. checked: 'false'
  83. } ],
  84. };
  85. },
  86. onLoad: function() {
  87. // #ifdef APP-PLUS
  88. var that = this
  89. plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
  90. that.version = wgtinfo.version
  91. });
  92. // #endif
  93. this.getCookie();
  94. this.loadingLogin();
  95. uni.getSystemInfo({
  96. success: function (res) {
  97. console.log(res.model);
  98. console.log(res.pixelRatio);
  99. console.log(res.windowWidth);
  100. console.log(res.windowHeight);
  101. console.log(res.language);
  102. console.log(res.version);
  103. console.log(res.system);
  104. }
  105. });
  106. },
  107. methods: {
  108. loadingLogin(){
  109. if(this.checkbox[1].checked=='true'){
  110. this.onLogin();
  111. }
  112. },
  113. //读取cookie
  114. getCookie: function() {
  115. if (document.cookie.length > 0) {
  116. var arr = document.cookie.split('; '); //这里显示的格式需要切割一下自己可输出看下
  117. for (var i = 0; i < arr.length; i++) {
  118. var arr2 = arr[i].split('='); //再次切割
  119. //判断查找相对应的值
  120. if (arr2[0] == 'userName') {
  121. this.userName = arr2[1]; //保存到保存数据的地方
  122. } else if (arr2[0] == 'userPwd') {
  123. this.password = arr2[1];
  124. } else if (arr2[0] == 'pwdchecked') {
  125. this.checkbox[0].checked = arr2[1];
  126. }
  127. }
  128. console.log(this.checkbox)
  129. }
  130. },
  131. //清除cookie
  132. setCookie(c_name, c_pwd, exdays, pwdche) {
  133. var exdate = new Date(); //获取时间
  134. exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays); //保存的天数
  135. //字符串拼接cookie
  136. window.document.cookie = "userName" + "=" + c_name + ";path=/;expires=" + exdate.toGMTString();
  137. window.document.cookie = "userPwd" + "=" + c_pwd + ";path=/;expires=" + exdate.toGMTString();
  138. window.document.cookie = "pwdchecked" + "=" + pwdche + ";path=/;expires=" + exdate.toGMTString();
  139. },
  140. checkboxChange: function(e) {
  141. var items = this.checkbox,
  142. values = e.detail.value;
  143. for (var i = 0, lenI = items.length; i < lenI; ++i) {
  144. items[i].checked = 'false';
  145. for (var j = 0, lenJ = values.length; j < lenJ; ++j) {
  146. if (items[i].value == values[j]) {
  147. items[i].checked = 'true';
  148. break
  149. }
  150. }
  151. }
  152. },
  153. ...mapActions(["mLogin", "PhoneLogin"]),
  154. onLogin: function() {
  155. if (!this.userName || this.userName.length == 0) {
  156. this.$tip.toast('请填写用户名');
  157. return;
  158. }
  159. if (!this.password || this.password.length == 0) {
  160. this.$tip.toast('请填写密码');
  161. return;
  162. }
  163. let loginParams = {
  164. username: this.userName,
  165. password: this.password
  166. }
  167. var pwd = this.checkbox;
  168. var uname="";
  169. var upwd="";
  170. var pwdCheked=false;
  171. if (this.checkbox[0].checked == 'true') {
  172. uname=this.userName;
  173. upwd=this.password;
  174. pwdCheked=true;
  175. }
  176. this.setCookie(uname,upwd,7,pwdCheked);
  177. this.loading = true;
  178. this.timeoutid=setTimeout(() => {
  179. if (this.loading == true) {
  180. this.exitloading = true;
  181. this.mLogin(loginParams).then((res) => {
  182. console.log("mLogin", res)
  183. if (res.data.success) {
  184. this.$tip.success('登录成功!')
  185. this.$Router.replaceAll({
  186. name: 'index'
  187. })
  188. } else {
  189. this.$tip.alert(res.data.message);
  190. }
  191. }).catch((err) => {
  192. let msg = err.data.message || "请求出现错误,请稍后再试"
  193. this.$tip.alert(msg);
  194. }).finally(() => {
  195. this.loading=false;
  196. })
  197. }
  198. }, 3000);
  199. /* this.$Router.push({name:'index'}) */
  200. }
  201. }
  202. }
  203. </script>
  204. <style>
  205. ul {
  206. margin-left: -60px;
  207. }
  208. ul li {
  209. list-style-type: none;
  210. display: inline;
  211. margin: 53px;
  212. }
  213. .map_container {
  214. height: 300px;
  215. width: 100%;
  216. }
  217. .map {
  218. height: 100%;
  219. width: 100%;
  220. }
  221. .login-paddingtop {
  222. padding-top: 200 upx;
  223. }
  224. .zai-box {
  225. padding: 0 20 upx;
  226. padding-top: 100 upx;
  227. position: relative;
  228. }
  229. .zai-logo {
  230. width: 30%;
  231. }
  232. .zai-title {
  233. font-size: 58upx;
  234. color: #000000;
  235. text-align: center;
  236. }
  237. .input-placeholder,
  238. .zai-input {
  239. color: #94afce;
  240. }
  241. .zai-label {
  242. padding: 60 upx 0;
  243. text-align: center;
  244. font-size: 30 upx;
  245. color: #a7b6d0;
  246. }
  247. .zai-btn {
  248. background: #ff65a3;
  249. color: #fff;
  250. border: 0;
  251. border-radius: 100 upx;
  252. font-size: 36 upx;
  253. }
  254. .zai-btn:after {
  255. border: 0;
  256. }
  257. /*按钮点击效果*/
  258. .zai-btn.button-hover {
  259. transform: translate(1 upx, 1 upx);
  260. }
  261. .divimg {
  262. background-image: url(../../static/home/beij3.jpeg);
  263. position: fixed;
  264. top: 0;
  265. left: 0;
  266. width: 100%;
  267. height: 100%;
  268. min-width: 1000px;
  269. z-index: -10;
  270. zoom: 1;
  271. background-repeat: no-repeat;
  272. background-size: cover;
  273. -webkit-background-size: cover;
  274. -o-background-size: cover;
  275. background-position: center0;
  276. }
  277. </style>