login.vue 16 KB

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