login.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <template>
  2. <view class="zai-box">
  3. <u-icon name="setting-fill" color="#2979ff" size="28" @click="setIp"></u-icon>
  4. <scroll-view scroll-y class="page" v-if="!ipShow">
  5. <view class="text-center" :style="[{ animation: 'show ' + 0.4 + 's 1' }]">
  6. <!-- <image src="/static/desk-img/logo.png" mode='aspectFit' class="zai-logo "></image> -->
  7. <image src="/static/dhz-logo.png" mode='aspectFit' class="zai-logo "></image>
  8. </view>
  9. <view class="text-center" :style="[{ animation: 'show ' + 0.4 + 's 1' }]">
  10. <!-- <u-link class="zai-title2 text-shadow " href="http://localhost:8080?ticket=234" >切换单点登录</u-link> -->
  11. <view class="zai-title2 text-shadow " @click="changeloginType">切换单点登录</view>
  12. </view>
  13. <view class="box padding-lr-xl login-paddingtop" :style="[{ animation: 'show ' + 0.6 + 's 1' }]">
  14. <block>
  15. <view class="cu-form-group margin-top shadow-warp" :class="[shape == 'round' ? 'round' : '']">
  16. <view class="title"><text class="cuIcon-people margin-right-xs"></text>账号:</view>
  17. <input placeholder="请输入账号" name="input" v-model="userName"></input>
  18. </view>
  19. <view class="cu-form-group margin-top shadow-warp" :class="[shape == 'round' ? 'round' : '']">
  20. <view class="title"><text class="cuIcon-lock margin-right-xs"></text>密码:</view>
  21. <input class="uni-input" placeholder="请输入密码" :password="!showPassword" v-model="password" />
  22. <view class="action text-lg">
  23. <text :class="[showPassword ? 'cuIcon-attention' : 'cuIcon-attentionforbid']"
  24. @click="changePassword"></text>
  25. </view>
  26. </view>
  27. <view class="padding text-center margin-top">
  28. <button class="cu-btn bg-blue lg margin-right shadow" :loading="loading"
  29. :class="[shape == 'round' ? 'round' : '']" @tap="onLogin"><text space="emsp">{{ loading ? "登录中..." :
  30. "登录" }}</text>
  31. </button>
  32. </view>
  33. </block>
  34. <!-- #ifdef APP-PLUS -->
  35. <view class="padding flex flex-direction text-center">
  36. 当前版本:{{ version }}
  37. </view>
  38. <!-- #endif -->
  39. </view>
  40. </scroll-view>
  41. <!-- 登录加载弹窗 -->
  42. <view class="cu-load load-modal" v-if="loading">
  43. <!-- <view class="cuIcon-emojifill text-orange"></view> -->
  44. <image src="/static/desk-img/144.png" mode="aspectFit" class="round"></image>
  45. <view class="gray-text">登录中...</view>
  46. </view>
  47. <scroll-view scroll-y class="page" v-if="ipShow">
  48. <!-- <view class="IPSet">
  49. <span class="text-style">IP地址: <u--input
  50. placeholder="请输入IP地址"
  51. border="surround"
  52. v-model="IPValue"
  53. ></u--input></span>
  54. <span class="text-style">端口号: <u--input
  55. placeholder="请输入端口号"
  56. border="surround"
  57. v-model="PortValue"
  58. ></u--input></span>
  59. <span class="text-style"><u-button :plain="true" color="#18a5ff" size="small" @tap="saveIP()">保存</u-button></span>
  60. </view> -->
  61. <!-- <scroll-view scroll-y class="page"> -->
  62. <view class="IPSet">
  63. <span class="text-style"><u-button :plain="true" color="#18a5ff" size="small" :text="IPSet ? IPSet : '选择IP地址'"
  64. @tap="changeIP()"></u-button></span>
  65. <u-picker :show="ipShow1" :columns="IpConfig" @cancel="ipShow = false" @confirm="selectIpAddr"
  66. keyName="label"></u-picker>
  67. </view>
  68. <!-- </scroll-view> -->
  69. </scroll-view>
  70. </view>
  71. </template>
  72. <script>
  73. import { ACCESS_TOKEN, USER_NAME, USER_INFO } from "@/common/util/constants";
  74. import { mapActions } from "vuex";
  75. import configService from "@/common/service/config.service.js";
  76. import { AesEncryption, getLoginCipher } from "@/common/util/cipher.js";
  77. import api from "@/api/api";
  78. export default {
  79. data() {
  80. return {
  81. ipShow: false,
  82. ipShow1: false,
  83. shape: "", //round 圆形
  84. loading: false,
  85. userName: "",
  86. password: "",
  87. phoneNo: "",
  88. smsCode: "",
  89. showPassword: false, //是否显示明文
  90. smsCountDown: 0,
  91. smsCountInterval: null,
  92. toggleDelay: false,
  93. version: "",
  94. //第三方登录相关信息
  95. thirdType: "",
  96. thirdLoginInfo: "",
  97. thirdLoginState: false,
  98. bindingPhoneModal: false,
  99. thirdUserUuid: "",
  100. IPValue: "",
  101. PortValue: "",
  102. fullIPVal: "", //完整IP地址
  103. IPSet: "",
  104. IpConfig: [
  105. [
  106. { label: "大海则煤矿", value: "http://172.16.53.16:9999" },
  107. { label: "大柳塔井", value: "http://10.248.135.10:9999" },
  108. { label: "活鸡兔井", value: "http://10.248.135.121:9999" },
  109. { label: "寸草塔二矿", value: "http://10.246.63.5:9999" },
  110. { label: "乌兰木伦", value: "http://10.246.183.35:9999" },
  111. { label: "哈拉沟煤矿", value: "http://10.248.223.12:9999" },
  112. { label: "布尔台", value: "http://10.246.95.4:9999" },
  113. { label: "上湾", value: "http://10.246.167.205:9999" },
  114. { label: "锦界", value: "http://10.248.151.42:9999" },
  115. { label: "补连塔", value: "http://10.246.175.16:9999" },
  116. { label: "寸草塔", value: "http://10.246.23.171:9999" },
  117. { label: "柳塔", value: "http://10.246.87.121:9999" },
  118. { label: "石圪台", value: "http://10.246.191.13:9999" },
  119. { label: "榆家梁", value: "http://10.248.143.211:9999" },
  120. { label: "开发", value: "http://182.92.126.35:9999" },
  121. { label: "测试", value: "http://182.92.126.35:9998" },
  122. ],
  123. ],
  124. };
  125. },
  126. onLoad: function (option) {
  127. console.log("=======option.ticket======" + JSON.stringify(option.ticket));
  128. this.loginCas(option.ticket);
  129. // #ifdef APP-PLUS
  130. var that = this;
  131. plus.runtime.getProperty(plus.runtime.appid, function (wgtinfo) {
  132. that.version = wgtinfo.version;
  133. });
  134. // #endif
  135. },
  136. computed: {
  137. isSendSMSEnable() {
  138. return this.smsCountDown <= 0 && this.phoneNo.length > 4;
  139. },
  140. getSendBtnText() {
  141. if (this.smsCountDown > 0) {
  142. return this.smsCountDown + "秒后发送";
  143. } else {
  144. return "发送验证码";
  145. }
  146. },
  147. canSMSLogin() {
  148. return this.userName.length > 4 && this.smsCode.length > 4;
  149. },
  150. canPwdLogin() {
  151. return this.userName.length > 4 && this.password.length > 4;
  152. },
  153. },
  154. methods: {
  155. ...mapActions(["mLogin", "PhoneLogin", "ThirdLogin"]),
  156. // 判断是否在APP环境中
  157. isApp() {
  158. return typeof plus !== "undefined";
  159. },
  160. onLogin: function () {
  161. if (!this.userName || this.userName.length == 0) {
  162. this.$tip.toast("请填写用户名");
  163. return;
  164. }
  165. if (!this.password || this.password.length == 0) {
  166. this.$tip.toast("请填写密码");
  167. return;
  168. }
  169. let loginParams = {
  170. username: this.userName,
  171. password: this.password,
  172. };
  173. // 加密
  174. const loginCipher = getLoginCipher();
  175. const encryption = new AesEncryption({
  176. key: loginCipher.key,
  177. iv: loginCipher.iv,
  178. });
  179. loginParams.password = encryption.encryptByAES(loginParams.password);
  180. this.loading = true;
  181. this.mLogin(loginParams)
  182. .then((res) => {
  183. this.loading = false;
  184. if (res.data.success) {
  185. if (this.isApp()) {
  186. // console.log('当前是APP环境');
  187. this.saveClientId();
  188. } else {
  189. this.getPermissionList();
  190. }
  191. // #ifdef APP-PLUS
  192. // #endif
  193. // #ifndef APP-PLUS
  194. // #endif
  195. } else {
  196. this.$tip.alert(res.data.message);
  197. }
  198. })
  199. .catch((err) => {
  200. let msg = err.data.message || "请求出现错误,请稍后再试";
  201. this.loading = false;
  202. this.$tip.alert(msg);
  203. })
  204. .finally(() => {
  205. this.loading = false;
  206. });
  207. },
  208. loginCas(value) {
  209. var than = this;
  210. // this.$tip.success(configService.apiUrl);
  211. var ser = configService.apiUrl;
  212. ser = ser.replace(9999, 8092);
  213. // this.$tip.success(ser);
  214. new Promise((resolve, reject) => {
  215. api
  216. .validateCasLogin(
  217. "",
  218. "?ticket=" + value + "&service=" + encodeURIComponent(ser)
  219. )
  220. .then((response) => {
  221. // than.$tip.success("登录成功1");
  222. // if (response.data.code == 200) {
  223. // uni.setStorageSync(ACCESS_TOKEN, response.data.result.token);
  224. // } else {
  225. // }
  226. const result = response.data.result;
  227. const userInfo = result.userInfo;
  228. uni.setStorageSync(ACCESS_TOKEN, result.token);
  229. uni.setStorageSync(USER_INFO, userInfo);
  230. console.log("userInfo=" + userInfo);
  231. than.$store.commit("SET_TOKEN", result.token);
  232. console.log("result.token=" + result.token);
  233. than.$store.commit("SET_DICT", result.sysAllDictItems);
  234. than.$store.commit("SET_AVATAR", userInfo.avatar);
  235. than.$store.commit("SET_NAME", {
  236. username: userInfo.username,
  237. realname: userInfo.realname,
  238. });
  239. // than.$tip.success("loginCas=");
  240. than.getPermissionList();
  241. })
  242. .catch((error) => {
  243. // debugger;
  244. console.log("catch===>response", error);
  245. // uni.navigateTo({
  246. // url: "/pages/home/home",
  247. // });
  248. });
  249. });
  250. },
  251. //获取权限菜单
  252. getPermissionList() {
  253. new Promise((resolve, reject) => {
  254. api
  255. .getPermission({})
  256. .then((response) => {
  257. console.log(response, "权限菜单----------------");
  258. if (response.statusCode == 200) {
  259. let data = response.data.result.menuApp;
  260. let dataBtn = response.data.result.appauth;
  261. uni.setStorageSync("menuPermission", data);
  262. uni.setStorageSync("btnPermission", dataBtn);
  263. this.$tip.success("登录成功!");
  264. uni.navigateTo({
  265. url: "/pages/index/index",
  266. });
  267. } else {
  268. reject(response);
  269. }
  270. })
  271. .catch((error) => {
  272. console.log("catch===>response", response);
  273. reject(error);
  274. });
  275. });
  276. },
  277. saveClientId() {
  278. this.getPermissionList();
  279. // var info = plus.push.getClientInfo();
  280. // var cid = info.clientid;
  281. // this.$http
  282. // .get("/sys/user/saveClientId", { params: { clientId: cid } })
  283. // .then((res) => {
  284. // console.log("res::saveClientId>", res);
  285. // //获取权限菜单
  286. // this.getPermissionList();
  287. // });
  288. },
  289. changePassword() {
  290. this.showPassword = !this.showPassword;
  291. },
  292. onSMSSend() {
  293. let smsParams = {};
  294. smsParams.mobile = this.phoneNo;
  295. smsParams.smsmode = "0";
  296. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  297. if (!smsParams.mobile || smsParams.mobile.length == 0) {
  298. this.$tip.toast("请输入手机号");
  299. return false;
  300. }
  301. if (!checkPhone.test(smsParams.mobile)) {
  302. this.$tip.toast("请输入正确的手机号");
  303. return false;
  304. }
  305. this.$http.post("/sys/sms", smsParams).then((res) => {
  306. if (res.data.success) {
  307. this.smsCountDown = 60;
  308. this.startSMSTimer();
  309. } else {
  310. this.smsCountDown = 0;
  311. this.$tip.toast(res.data.message);
  312. }
  313. });
  314. },
  315. startSMSTimer() {
  316. this.smsCountInterval = setInterval(() => {
  317. this.smsCountDown--;
  318. if (this.smsCountDown <= 0) {
  319. clearInterval(this.smsCountInterval);
  320. }
  321. }, 1000);
  322. },
  323. onSMSLogin() {
  324. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  325. if (!this.phoneNo || this.phoneNo.length == 0) {
  326. this.$tip.toast("请填写手机号");
  327. return;
  328. }
  329. if (!checkPhone.test(this.phoneNo)) {
  330. this.$tip.toast("请输入正确的手机号");
  331. return false;
  332. }
  333. if (!this.smsCode || this.smsCode.length == 0) {
  334. this.$tip.toast("请填短信验证码");
  335. return;
  336. }
  337. let loginParams = {
  338. mobile: this.phoneNo,
  339. captcha: this.smsCode,
  340. };
  341. this.PhoneLogin(loginParams)
  342. .then((res) => {
  343. console.log("res====》", res);
  344. if (res.data.success) {
  345. this.$tip.success("登录成功!");
  346. uni.navigateTo({
  347. url: "/pages/inedx/inedx",
  348. });
  349. } else {
  350. this.$tip.error(res.data.message);
  351. }
  352. })
  353. .catch((err) => {
  354. let msg =
  355. ((err.response || {}).data || {}).message ||
  356. err.data.message ||
  357. "请求出现错误,请稍后再试";
  358. this.$tip.error(msg);
  359. });
  360. },
  361. loginSuccess() {
  362. // 登陆成功,重定向到主页
  363. this.$Router.replace({ name: "index" });
  364. },
  365. requestFailed(err) {
  366. this.$message.warning("登录失败");
  367. },
  368. changeloginType() {
  369. console.log("changeloginType====");
  370. var tourl = configService.apiUrl;
  371. tourl = tourl.replace(9999, 8092);
  372. // this.$tip.success("tourl="+tourl);
  373. var rastourl =
  374. "https://id.shendong.com.cn/default" + "/login?service=" + tourl;
  375. // rastourl ="http://182.92.126.35:8092/?ticket=234";
  376. console.log("===========" + rastourl);
  377. this.openBrowser(rastourl);
  378. // window.location.href='/pages/index/index?ticket=123'
  379. // this.$router.push({ path: '/pages/index/index?ticket=123',query:"2w354" })
  380. },
  381. openBrowser(url) {
  382. // 使用uni.navigateTo打开内置浏览器
  383. console.log("----url---------------" + url);
  384. // this.$tip.success("url="+url);
  385. uni.navigateTo({
  386. url: "/pages/webview/webview?url=" + encodeURIComponent(url),
  387. });
  388. },
  389. // setIp() {
  390. // uni.navigateTo({
  391. // url: "/pages/ipConfig/ipConfig",
  392. // });
  393. // },
  394. //正则判断ip地址
  395. validateIP(ip) {
  396. const regex =
  397. /^(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)){3}$/;
  398. return regex.test(ip);
  399. },
  400. //正则判断端口地址
  401. validatePort(port) {
  402. const regex = /^([1-9]\d{0,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])$/;
  403. return regex.test(port);
  404. },
  405. setIp() {
  406. console.log("点击成功");
  407. this.ipShow = !this.ipShow;
  408. },
  409. saveIP() {
  410. this.validateIP(this.IPValue);
  411. this.validatePort(this.PortValue);
  412. if (this.validateIP(this.IPValue) && this.validatePort(this.PortValue)) {
  413. this.ipShow = false;
  414. this.fullIPVal = `http://${this.IPValue}:${this.PortValue}`;
  415. configService.apiUrl = this.fullIPVal;
  416. uni.setStorageSync("apiUrl", configService.apiUrl);
  417. // localStorage.setItem("apiUrl", apiUrl);
  418. } else if (!this.validateIP(this.IPValue)) {
  419. alert("请填写正确的IP地址");
  420. } else if (!this.validatePort(this.PortValue)) {
  421. alert("请填写正确的端口号");
  422. } else {
  423. alert("请检查输入的IP地址或端口号");
  424. }
  425. },
  426. changeIP() {
  427. this.ipShow1 = true;
  428. },
  429. selectIpAddr(e) {
  430. this.ipShow1 = false;
  431. const fullURL = e.value[0].value;
  432. this.IPSet = e.value[0].label;
  433. configService.apiUrl = fullURL;
  434. uni.setStorageSync("apiUrl", configService.apiUrl);
  435. setTimeout(() => {
  436. uni.getStorageSync("apiUrl");
  437. }, 100);
  438. uni.navigateTo({ url: "/pages/login/login" });
  439. },
  440. },
  441. beforeDestroy() {
  442. if (this.smsCountInterval) {
  443. clearInterval(this.smsCountInterval);
  444. }
  445. },
  446. };
  447. </script>
  448. <style>
  449. .login-paddingtop {
  450. padding-top: 300upx;
  451. }
  452. .zai-box {
  453. height: 100vh;
  454. background-image: url(/static/desk-img/loginBg.png);
  455. background-size: cover;
  456. padding: 0 20upx;
  457. padding-top: 100upx;
  458. position: relative;
  459. }
  460. .zai-logo {
  461. width: 200upx;
  462. height: 150px;
  463. }
  464. .zai-title {
  465. margin-top: 20upx;
  466. font-size: 58upx;
  467. color: #000000;
  468. text-align: center;
  469. }
  470. .input-placeholder,
  471. .zai-input {
  472. color: #94afce;
  473. }
  474. .zai-btn {
  475. background: #ff65a3;
  476. color: #fff;
  477. border: 0;
  478. border-radius: 100upx;
  479. font-size: 36upx;
  480. }
  481. .zai-btn:after {
  482. border: 0;
  483. }
  484. /*按钮点击效果*/
  485. .zai-btn.button-hover {
  486. transform: translate(1upx, 1upx);
  487. }
  488. .IPSet {
  489. display: flex;
  490. flex-direction: column;
  491. }
  492. .text-style {
  493. margin: 20px;
  494. }
  495. </style>