login.vue 8.9 KB

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