login.vue 16 KB

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