login.vue 17 KB

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