login.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. <template>
  2. <div class="login-box" :style="'height:' + fullHeight + 'px'" v-loading="loading">
  3. <img src="../assets/imageOne/222.jpg" alt class />
  4. <div class="piece">
  5. <!-- title -->
  6. <div class="title">
  7. <!-- <div class="title-text">病虫测报数据采集系统</div> -->
  8. <div class="title-text">虫害识别系统</div>
  9. </div>
  10. <!-- input -->
  11. <div class="login" v-if="inptShow">
  12. <el-form :model="ruleForm" ref="ruleForm" label-width="50px" class="demo-ruleForm">
  13. <el-form-item prop="username">
  14. <el-input
  15. v-model="ruleForm.username"
  16. ref="input1"
  17. maxlength="11"
  18. placeholder="请输入账户"
  19. clearable
  20. prefix-icon="el-icon-mobile-phone"
  21. autocomplete="on"
  22. ></el-input>
  23. </el-form-item>
  24. <div class="paswd_box">
  25. <img src="../../static/suo.png" alt class="paswd_box_imgA" />
  26. <div class v-if="pwdType">
  27. <input
  28. class="paswd_ipt pasword"
  29. type="password"
  30. v-model="ruleForm.password"
  31. placeholder="请输入密码"
  32. ref="input2"
  33. />
  34. </div>
  35. <div class v-else>
  36. <input
  37. class="paswd_ipt textword"
  38. type="text"
  39. v-model="ruleForm.password"
  40. placeholder="请输入密码"
  41. ref="input2"
  42. />
  43. </div>
  44. <img :src="seen ? seenImg : unseenImg" @click="changeType()" class="paswd_box_imgB" />
  45. </div>
  46. <div class="box clearfix">
  47. <div class="automate">
  48. <el-checkbox v-model="checked" style="color:#a0a0a0;">
  49. <span class="automate_text">记住密码</span>
  50. </el-checkbox>
  51. </div>
  52. </div>
  53. <el-form-item>
  54. <el-button type="primary" @click.13="login()">
  55. <i class="el-icon-loading" v-show="iShow"></i>
  56. 登录
  57. </el-button>
  58. </el-form-item>
  59. </el-form>
  60. </div>
  61. <!-- 首次登陆时要输入验证码 -->
  62. <div class="verification_box" v-else>
  63. <!-- <div class="verify_text">请先输入验证码,验证成功后才能进入程序进行操作</div> -->
  64. <el-input
  65. v-if="iptSHow"
  66. class="verify_ipt verification"
  67. placeholder="请输入激活码,激活成功后才可进入程序"
  68. v-model="inputV"
  69. clearable
  70. ></el-input>
  71. <!-- <el-input v-else class="verify_ipt verification" readonly=true v-model="inputV" clearable></el-input> -->
  72. <el-input v-else class="verify_ipt verification" v-model="inputV" clearable></el-input>
  73. <div class="verify_btn">
  74. <el-button type="primary" @click.13="verify()">
  75. <i class="el-icon-loading" v-show="iShow"></i>
  76. 提交
  77. </el-button>
  78. </div>
  79. </div>
  80. <!-- 更新提示弹框-->
  81. <el-dialog title="提示" :visible.sync="dialogVisible" width="60%">
  82. <span>是否更新到最新版本</span>
  83. <span slot="footer" class="dialog-footer">
  84. <div class="login-box_div">
  85. <!-- 测试 -->
  86. <el-button @click="dialogVisible = false, offApp()" class="kunchongBtn">取 消</el-button>
  87. </div>
  88. <div class="login-box_div">
  89. <!-- 测试 -->
  90. <el-button @click="dialogVisible = false, newApp()" class="binghaiBtn">确 定</el-button>
  91. </div>
  92. </span>
  93. </el-dialog>
  94. <!-- 进度条 -->
  95. <div class="schedule_box" v-if="scheduleShow" :style="'height:' + fullHeight + 'px'">
  96. <div class="schedule_box_div">
  97. <div class="schedule_box_title">正在下载...</div>
  98. <el-progress :percentage="percentage" :color="customColors"></el-progress>
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103. </template>
  104. <script>
  105. function filterInput(val) {
  106. // 这里过滤的是除了英文字母和数字的其他字符
  107. return val.replace(/[^A-z0-9]/, "");
  108. }
  109. import VueInputCode from "vue-input-code"; //验证码样式
  110. export default {
  111. name: "login",
  112. data() {
  113. let self = this;
  114. return {
  115. isClick: true,
  116. loading: true, //加载
  117. ruleForm: {
  118. username: "",
  119. password: ""
  120. },
  121. seen: "",
  122. checked: false,
  123. iShow: false, //登录缓冲图标
  124. fullHeight: document.documentElement.clientHeight,
  125. unseenImg: "./static/eyes.png", //看不见
  126. seenImg: "./static/eye.png", //看得见密码
  127. pwdType: true, //此时文本框隐藏,显示密码框
  128. loaded: false,
  129. center: [121.59996, 31.197646],
  130. lng: 0,
  131. lat: 0,
  132. // loaded: false,
  133. timer: "", //定时器
  134. checked: false, //记住密码多选框
  135. dialogVisible: false, //更新弹框
  136. scheduleShow: false, //进度条
  137. redataName: "", //获取到后端发来的app的名字
  138. //测试进度条
  139. percentage: 0,
  140. customColor: "#409eff",
  141. customColors: [
  142. { color: "#f56c6c", percentage: 5 },
  143. { color: "#e6a23c", percentage: 10 },
  144. { color: "#5cb87a", percentage: 20 },
  145. { color: "#1989fa", percentage: 30 },
  146. { color: "#6f7ad3", percentage: 40 },
  147. { color: "#f56c6c", percentage: 50 },
  148. { color: "#e6a23c", percentage: 60 },
  149. { color: "#5cb87a", percentage: 70 },
  150. { color: "#1989fa", percentage: 80 },
  151. { color: "#6f7ad3", percentage: 90 },
  152. { color: "#6f7ad3", percentage: 100 }
  153. ],
  154. radio: "1", //账号身份的单选
  155. inptShow: false, //激活验证码显示登陆按钮
  156. inputV: "", //验证码
  157. iptSHow: true //判断当前设备是否激活过
  158. };
  159. },
  160. components: {
  161. VueInputCode
  162. },
  163. watch: {
  164. fullHeight(val) {
  165. //监控浏览器高度变化
  166. if (!this.timer) {
  167. this.fullHeight = val;
  168. this.timer = true;
  169. let that = this;
  170. setTimeout(function() {
  171. //防止过度调用监测事件,导致卡顿
  172. that.timer = false;
  173. }, 400);
  174. }
  175. },
  176. //判断进度条是否为100%
  177. percentage(time) {
  178. if (time === 100) {
  179. this.scheduleShow = false;
  180. this.$message({
  181. message: "已经下载成功,可以安装",
  182. type: "success",
  183. duration: 1000
  184. });
  185. }
  186. },
  187. // //监听账号
  188. // "ruleForm.username"(val) {
  189. // this.$nextTick(() => {
  190. // this.ruleForm.username = filterInput(val);
  191. // });
  192. // },
  193. //监听密码
  194. "ruleForm.password"(val) {
  195. this.$nextTick(() => {
  196. this.ruleForm.password = filterInput(val);
  197. });
  198. }
  199. },
  200. created() {
  201. this.getLocalStorage(); //页面加载调用获取LocalStorage值
  202. },
  203. mounted() {
  204. let _this = this;
  205. _this.get_boderHeight();
  206. _this.ceshi();
  207. // _this
  208. // .$axios({
  209. // method: "get",
  210. // url: "bigservers/app_upgrade"
  211. // })
  212. // .then(res => {
  213. // if (res.data.app_num === "1.1.7") {
  214. // } else if (res.data.app_num > "1.1.7") {
  215. // this.$message({
  216. // message: "检测到有新版本",
  217. // type: "success",
  218. // duration: 1000
  219. // });
  220. // _this.dialogVisible = true;
  221. // localStorage.setItem("redataName", res.data.app_name);
  222. // _this.redataName = res.data.app_name;
  223. // console.log(res.data.app_name);
  224. // }
  225. // })
  226. // .catch(error => {});
  227. },
  228. methods: {
  229. //动态获取浏览器高度
  230. get_boderHeight() {
  231. const that = this;
  232. window.onresize = () => {
  233. return (() => {
  234. window.fullHeight = document.documentElement.clientHeight;
  235. that.fullHeight = window.fullHeight;
  236. })();
  237. };
  238. },
  239. ceshi() {
  240. //判断用户是否激活app
  241. var _this = this;
  242. var uuID = localStorage.getItem("uuID");
  243. console.log(localStorage.getItem("uuID") + "还未请求时的参数");
  244. let postData = this.$qs.parse({
  245. imei: uuID
  246. });
  247. _this
  248. .$axios({
  249. method: "post",
  250. url: "bigservers/decide",
  251. data: postData
  252. })
  253. .then(res => {
  254. console.log("请求成功了");
  255. console.log(localStorage.getItem("uuID") + "请求成功的参数");
  256. if (res.data !== null && res.data !== 2 && res.data !== 0) {
  257. _this.inptShow = true;
  258. _this.inputV = res.data[0].cipher;
  259. _this.loading = false;
  260. console.log("已经注册过了");
  261. } else if (res.data == 2) {
  262. //还未注册
  263. _this.inptShow = false; //登录按钮
  264. _this.iptSHow = true;
  265. _this.loading = false;
  266. console.log("需要填写验证码");
  267. } else if (localStorage.getItem("uuID") == null) {
  268. this.$alert("获取设备信息失败,请重启软件", "提示", {
  269. confirmButtonText: "确定",
  270. callback: action => {
  271. var webview = plus.webview.currentWebview(); //获取当前页面的
  272. plus.runtime.quit(); //退出应用
  273. }
  274. });
  275. }
  276. })
  277. .catch(error => {});
  278. },
  279. //密码的显示隐藏
  280. changeType() {
  281. this.seen = !this.seen; //小眼睛的变化
  282. this.pwdType = !this.pwdType; //跟着小眼睛变化,密码框隐藏显示文本框,内容就显示了
  283. },
  284. setLocalStorage(u, p) {
  285. localStorage.setItem("Name", u);
  286. localStorage.setItem("passWord", p);
  287. },
  288. //读取localStorage
  289. getLocalStorage() {
  290. let _this = this;
  291. if (
  292. localStorage.getItem("Name") !== null &&
  293. localStorage.getItem("passWord") !== null
  294. ) {
  295. _this.ruleForm.username = localStorage.getItem("Name");
  296. _this.ruleForm.password = localStorage.getItem("passWord");
  297. _this.checked = true;
  298. }
  299. },
  300. //清除localStorage
  301. clearLocalStorage() {
  302. localStorage.removeItem("Name");
  303. localStorage.removeItem("passWord");
  304. },
  305. // 登录
  306. login() {
  307. let _this = this;
  308. _this.username = _this.$refs.input1.value; //获取input
  309. _this.password = _this.$refs.input2.value;
  310. var isClick = _this.isClick;
  311. if (isClick === true) {
  312. _this.isClick = false;
  313. if (_this.ruleForm.username === "" || _this.ruleForm.password === "") {
  314. this.$notify({
  315. title: "失败",
  316. message: "账号密码不能为空",
  317. type: "error",
  318. duration: 1000
  319. });
  320. } else {
  321. let login = this.$qs.stringify({
  322. username: this.username,
  323. password: this.password
  324. });
  325. this.iShow = true;
  326. this.$axios({
  327. method: "post",
  328. url: "bigservers/app_log",
  329. data: login
  330. }).then(res => {
  331. if (res.data !== 1 && res.data !== 2) {
  332. //判断用户是否没有把app升级到最新版本
  333. if (sessionStorage.getItem("offApp") === null) {
  334. sessionStorage.setItem("login", this.ruleForm.username);
  335. this.iShow = false;
  336. this.$notify({
  337. title: "成功",
  338. message: "您已成功登陆",
  339. type: "success",
  340. duration: 1000
  341. });
  342. this.$router.replace("/home");
  343. if (_this.checked == true) {
  344. _this.setLocalStorage(
  345. _this.ruleForm.username,
  346. _this.ruleForm.password
  347. );
  348. } else {
  349. //清空localStorage
  350. _this.clearLocalStorage();
  351. }
  352. //判断账号是什么身份
  353. if (
  354. res.data[0].is_active === true &&
  355. res.data[0].is_staff === true &&
  356. res.data[0].is_superuser === true
  357. ) {
  358. console.log("这是管理者");
  359. sessionStorage.setItem("Administrator", "管理员"); //管理员
  360. sessionStorage.removeItem("common");
  361. } else {
  362. console.log("这是普通用户");
  363. sessionStorage.setItem("common", "普通用户"); //普通用户
  364. sessionStorage.removeItem("Administrator");
  365. }
  366. _this
  367. .$axios({
  368. method: "get",
  369. url: "bigservers/app_user_in"
  370. })
  371. .then(res => {
  372. localStorage.setItem(
  373. "personAxios",
  374. JSON.stringify(res.data)
  375. );
  376. })
  377. .catch(error => {
  378. this.$notify({
  379. title: "失败",
  380. message: "请求失败",
  381. type: "error",
  382. duration: 1000
  383. });
  384. });
  385. //
  386. if (localStorage.getItem("personAxios") !== null) {
  387. _this.isShow = true;
  388. } else {
  389. _this.isShow = false;
  390. }
  391. } else if (sessionStorage.getItem("offApp") !== null) {
  392. this.$notify({
  393. title: "警告",
  394. message: "请您先升级到最新版",
  395. type: "error",
  396. duration: 1000
  397. });
  398. const timer = setInterval(() => {
  399. this.iShow = false;
  400. }, 3000);
  401. }
  402. } else if (res.data === 1) {
  403. console.log("失败");
  404. this.$notify({
  405. title: "失败",
  406. message: "用户名错误或用户不存在",
  407. type: "error",
  408. duration: 1000
  409. });
  410. console.log("error submit!!");
  411. const timer = setInterval(() => {
  412. this.iShow = false;
  413. }, 3000);
  414. return false;
  415. } else if (res.data === 2) {
  416. console.log("失败1");
  417. this.$notify({
  418. title: "失败",
  419. message: "密码错误",
  420. type: "error",
  421. duration: 1000
  422. });
  423. console.log("error submit!!");
  424. const timer = setInterval(() => {
  425. this.iShow = false;
  426. }, 3000);
  427. return false;
  428. }
  429. });
  430. }
  431. setTimeout(function() {
  432. _this.isClick = true;
  433. }, 1500);
  434. }
  435. },
  436. //升级到最新版本弹框
  437. newApp() {
  438. // console.log(this.redataName);
  439. // window.location.href =
  440. // "bigservers/app_file/" + this.redataName;
  441. // this.scheduleShow = true;
  442. // const timer = setInterval(() => {
  443. // this.percentage += 10;
  444. // if (this.percentage > 100) {
  445. // this.percentage = 100;
  446. // }
  447. // }, 4000);
  448. // var wait = plus.nativeUI.showWaiting("下载更新中,请勿关闭");
  449. // //创建一个下载任务
  450. // var dtask = plus.downloader.createDownload(
  451. // "bigservers/app_file/" + this.redataName,
  452. // {
  453. // method: "GET"
  454. // },
  455. // function(d, status) {
  456. // if (status == 200) {
  457. // console.log("Download success: " + d.filename);
  458. // plus.runtime.install(d.filename); // 安装下载的apk文件
  459. // } else {
  460. // alert("更新失败");
  461. // // plus.runtime.install('../H5B2852C7_0925104810.apk'); // 安装下载的apk文件
  462. // }
  463. // wait.close();
  464. // }
  465. // );
  466. // //开始下载
  467. // dtask.start();
  468. },
  469. //关闭app
  470. offApp() {
  471. // window.location.href = "about:blank";
  472. // window.close();
  473. sessionStorage.setItem("offApp", "1"); //在本地存一个标识如果有这个标识,用户就不能进入home进行操作
  474. },
  475. //点击提交验证码
  476. verify() {
  477. let _this = this;
  478. var isClick = _this.isClick;
  479. if (isClick === true) {
  480. _this.isClick = false;
  481. let postData = _this.$qs.parse({
  482. num: _this.inputV,
  483. imei: localStorage.getItem("uuID")
  484. });
  485. _this
  486. .$axios({
  487. method: "post",
  488. url: "bigservers/census",
  489. data: postData
  490. })
  491. .then(res => {
  492. if (res.data === 0) {
  493. //没有获取手机meid
  494. this.$notify.error({
  495. title: "失败",
  496. message: "验证失败",
  497. duration: 1000
  498. });
  499. } else if (res.data === 1) {
  500. //该手机已绑定其它验证码
  501. this.$notify.error({
  502. title: "失败",
  503. message: "该手机已绑定其它验证码",
  504. duration: 1000
  505. });
  506. } else if (res.data === 2) {
  507. // 验证码输入错误
  508. this.$notify.error({
  509. title: "失败",
  510. message: " 验证码输入错误",
  511. duration: 1000
  512. });
  513. } else if (res.data === 3) {
  514. //该验证码已绑定其它手机号
  515. this.$notify.error({
  516. title: "失败",
  517. message: " 该验证码已绑定其它手机号",
  518. duration: 1000
  519. });
  520. } else if (res.data === 4) {
  521. //绑定验证码
  522. this.$notify({
  523. title: "成功",
  524. message: "绑定成功",
  525. duration: 2000,
  526. type: "success"
  527. });
  528. _this.inptShow = true;
  529. localStorage.setItem("decide", "1"); //存储一个标识,进行判断当前需要显示激活码
  530. } else if (res.data === 5) {
  531. //验证成功
  532. this.$notify({
  533. title: "成功",
  534. message: "验证成功",
  535. duration: 1000,
  536. type: "success"
  537. });
  538. _this.inptShow = true;
  539. localStorage.setItem("decide", "1"); //存储一个标识,进行判断当前需要显示激活码
  540. }
  541. })
  542. .catch(error => {
  543. this.$notify.error({
  544. title: "失败",
  545. message: "验证失败",
  546. duration: 1000
  547. });
  548. });
  549. setTimeout(function() {
  550. _this.isClick = true;
  551. }, 1500);
  552. }
  553. }
  554. }
  555. };
  556. </script>
  557. <style lang="scss">
  558. @import "../assets/style/bus.scss";
  559. @import "../assets/style/scss/login.scss";
  560. </style>