login.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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 " @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="ipShow">
  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. { label: "准东二矿", value: "http://172.19.7.101:9999", code: 'zdrk' },
  108. { label: "大海则煤矿", value: "http://172.16.53.16:9999", code: 'dhz' },
  109. { label: "大柳塔井", value: "http://10.248.135.10:9999", code: 'dlt' },
  110. { label: "活鸡兔井", value: "http://10.248.135.121:9999", code: 'hjt' },
  111. { label: "寸草塔二矿", value: "http://10.246.63.5:9999", code: 'cctr' },
  112. { label: "乌兰木伦", value: "http://10.246.183.35:9999", code: 'wlml' },
  113. { label: "哈拉沟煤矿", value: "http://10.248.223.12:9999", code: 'hlg' },
  114. { label: "布尔台", value: "http://10.246.95.4:9999", code: 'brt' },
  115. { label: "上湾", value: "http://10.246.167.205:9999", code: 'sw' },
  116. { label: "锦界", value: "http://10.248.151.42:9999", code: 'jj' },
  117. { label: "补连塔", value: "http://10.246.175.16:9999", code: 'blt' },
  118. { label: "寸草塔", value: "http://10.246.23.171:9999", code: 'cct' },
  119. { label: "柳塔", value: "http://10.246.87.121:9999", code: 'lt' },
  120. { label: "石圪台", value: "http://10.246.191.13:9999", code: 'sgt' },
  121. { label: "榆家梁", value: "http://10.248.143.211:9999", code: 'yjl' },
  122. { label: "开发", value: "http://182.92.126.35:9999", code: 'kf' },
  123. { label: "测试", value: "http://182.92.126.35:9998", code: 'cs' },
  124. { label: "特拉布拉", value: "http://10.7.0.19:9999", code: 'lblt' },
  125. ],
  126. ],
  127. };
  128. },
  129. onLoad: function (option) {
  130. console.log("=======option.ticket======" + JSON.stringify(option.ticket));
  131. this.loginCas(option.ticket);
  132. // #ifdef APP-PLUS
  133. var that = this;
  134. plus.runtime.getProperty(plus.runtime.appid, function (wgtinfo) {
  135. that.version = wgtinfo.version;
  136. });
  137. // #endif
  138. },
  139. computed: {
  140. isSendSMSEnable() {
  141. return this.smsCountDown <= 0 && this.phoneNo.length > 4;
  142. },
  143. getSendBtnText() {
  144. if (this.smsCountDown > 0) {
  145. return this.smsCountDown + "秒后发送";
  146. } else {
  147. return "发送验证码";
  148. }
  149. },
  150. canSMSLogin() {
  151. return this.userName.length > 4 && this.smsCode.length > 4;
  152. },
  153. canPwdLogin() {
  154. return this.userName.length > 4 && this.password.length > 4;
  155. },
  156. },
  157. methods: {
  158. ...mapActions(["mLogin", "PhoneLogin", "ThirdLogin"]),
  159. // 判断是否在APP环境中
  160. isApp() {
  161. return typeof plus !== "undefined";
  162. },
  163. onLogin: function () {
  164. if (!this.userName || this.userName.length == 0) {
  165. this.$tip.toast("请填写用户名");
  166. return;
  167. }
  168. if (!this.password || this.password.length == 0) {
  169. this.$tip.toast("请填写密码");
  170. return;
  171. }
  172. let loginParams = {
  173. username: this.userName,
  174. password: this.password,
  175. clientId: uni.getStorageSync('push_cid')
  176. };
  177. // 加密
  178. const loginCipher = getLoginCipher();
  179. const encryption = new AesEncryption({
  180. key: loginCipher.key,
  181. iv: loginCipher.iv,
  182. });
  183. loginParams.password = encryption.encryptByAES(loginParams.password);
  184. this.loading = true;
  185. this.mLogin(loginParams)
  186. .then((res) => {
  187. this.loading = false;
  188. if (res.data.success) {
  189. if (this.isApp()) {
  190. // console.log('当前是APP环境');
  191. this.saveClientId();
  192. } else {
  193. this.getPermissionList();
  194. }
  195. // #ifdef APP-PLUS
  196. // #endif
  197. // #ifndef APP-PLUS
  198. // #endif
  199. } else {
  200. this.$tip.alert(res.data.message);
  201. }
  202. })
  203. .catch((err) => {
  204. let msg = err.data.message || "请求出现错误,请稍后再试";
  205. this.loading = false;
  206. this.$tip.alert(msg);
  207. })
  208. .finally(() => {
  209. this.loading = false;
  210. });
  211. },
  212. loginCas(value) {
  213. var than = this;
  214. // this.$tip.success(configService.apiUrl);
  215. var ser = configService.apiUrl;
  216. ser = ser.replace(9999, 8092);
  217. // this.$tip.success(ser);
  218. new Promise((resolve, reject) => {
  219. api
  220. .validateCasLogin(
  221. "",
  222. "?ticket=" + value + "&service=" + encodeURIComponent(ser)
  223. )
  224. .then((response) => {
  225. // than.$tip.success("登录成功1");
  226. // if (response.data.code == 200) {
  227. // uni.setStorageSync(ACCESS_TOKEN, response.data.result.token);
  228. // } else {
  229. // }
  230. const result = response.data.result;
  231. const userInfo = result.userInfo;
  232. uni.setStorageSync(ACCESS_TOKEN, result.token);
  233. uni.setStorageSync(USER_INFO, userInfo);
  234. console.log("userInfo=" + userInfo);
  235. than.$store.commit("SET_TOKEN", result.token);
  236. console.log("result.token=" + result.token);
  237. than.$store.commit("SET_DICT", result.sysAllDictItems);
  238. than.$store.commit("SET_AVATAR", userInfo.avatar);
  239. than.$store.commit("SET_NAME", {
  240. username: userInfo.username,
  241. realname: userInfo.realname,
  242. });
  243. // than.$tip.success("loginCas=");
  244. than.getPermissionList();
  245. })
  246. .catch((error) => {
  247. // debugger;
  248. console.log("catch===>response", error);
  249. // uni.navigateTo({
  250. // url: "/pages/home/home",
  251. // });
  252. });
  253. });
  254. },
  255. //获取权限菜单
  256. getPermissionList() {
  257. new Promise((resolve, reject) => {
  258. api
  259. .getPermission({})
  260. .then((response) => {
  261. console.log(response, "权限菜单----------------");
  262. if (response.statusCode == 200) {
  263. let data = response.data.result.menuApp;
  264. let dataBtn = response.data.result.appauth;
  265. uni.setStorageSync("menuPermission", data);
  266. uni.setStorageSync("btnPermission", dataBtn);
  267. this.$tip.success("登录成功!");
  268. uni.navigateTo({
  269. url: "/pages/index/index",
  270. });
  271. } else {
  272. reject(response);
  273. }
  274. })
  275. .catch((error) => {
  276. console.log("catch===>response", response);
  277. reject(error);
  278. });
  279. });
  280. },
  281. saveClientId() {
  282. this.getPermissionList();
  283. // var info = plus.push.getClientInfo();
  284. // var cid = info.clientid;
  285. // this.$http
  286. // .get("/sys/user/saveClientId", { params: { clientId: cid } })
  287. // .then((res) => {
  288. // console.log("res::saveClientId>", res);
  289. // //获取权限菜单
  290. // this.getPermissionList();
  291. // });
  292. },
  293. changePassword() {
  294. this.showPassword = !this.showPassword;
  295. },
  296. onSMSSend() {
  297. let smsParams = {};
  298. smsParams.mobile = this.phoneNo;
  299. smsParams.smsmode = "0";
  300. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  301. if (!smsParams.mobile || smsParams.mobile.length == 0) {
  302. this.$tip.toast("请输入手机号");
  303. return false;
  304. }
  305. if (!checkPhone.test(smsParams.mobile)) {
  306. this.$tip.toast("请输入正确的手机号");
  307. return false;
  308. }
  309. this.$http.post("/sys/sms", smsParams).then((res) => {
  310. if (res.data.success) {
  311. this.smsCountDown = 60;
  312. this.startSMSTimer();
  313. } else {
  314. this.smsCountDown = 0;
  315. this.$tip.toast(res.data.message);
  316. }
  317. });
  318. },
  319. startSMSTimer() {
  320. this.smsCountInterval = setInterval(() => {
  321. this.smsCountDown--;
  322. if (this.smsCountDown <= 0) {
  323. clearInterval(this.smsCountInterval);
  324. }
  325. }, 1000);
  326. },
  327. onSMSLogin() {
  328. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  329. if (!this.phoneNo || this.phoneNo.length == 0) {
  330. this.$tip.toast("请填写手机号");
  331. return;
  332. }
  333. if (!checkPhone.test(this.phoneNo)) {
  334. this.$tip.toast("请输入正确的手机号");
  335. return false;
  336. }
  337. if (!this.smsCode || this.smsCode.length == 0) {
  338. this.$tip.toast("请填短信验证码");
  339. return;
  340. }
  341. let loginParams = {
  342. mobile: this.phoneNo,
  343. captcha: this.smsCode,
  344. };
  345. this.PhoneLogin(loginParams)
  346. .then((res) => {
  347. console.log("res====》", res);
  348. if (res.data.success) {
  349. this.$tip.success("登录成功!");
  350. uni.navigateTo({
  351. url: "/pages/inedx/inedx",
  352. });
  353. } else {
  354. this.$tip.error(res.data.message);
  355. }
  356. })
  357. .catch((err) => {
  358. let msg =
  359. ((err.response || {}).data || {}).message ||
  360. err.data.message ||
  361. "请求出现错误,请稍后再试";
  362. this.$tip.error(msg);
  363. });
  364. },
  365. loginSuccess() {
  366. // 登陆成功,重定向到主页
  367. this.$Router.replace({ name: "index" });
  368. },
  369. requestFailed(err) {
  370. this.$message.warning("登录失败");
  371. },
  372. changeloginType() {
  373. console.log("changeloginType====");
  374. console.log(configService, "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. console.log("点击成功");
  396. this.ipShow = !this.ipShow;
  397. },
  398. changeIP() {
  399. this.ipShow1 = true;
  400. },
  401. selectIpAddr(e) {
  402. this.ipShow1 = false;
  403. const fullURL = e.value[0].value;
  404. this.IPSet = e.value[0].label;
  405. const apiCode = e.value[0].code
  406. configService.apiUrl = fullURL;
  407. uni.setStorageSync("apiUrl", configService.apiUrl);
  408. uni.setStorageSync("apiCode", apiCode);
  409. setTimeout(() => {
  410. uni.getStorageSync("apiUrl");
  411. }, 100);
  412. uni.navigateTo({ url: "/pages/login/login" });
  413. },
  414. },
  415. beforeDestroy() {
  416. if (this.smsCountInterval) {
  417. clearInterval(this.smsCountInterval);
  418. }
  419. },
  420. };
  421. </script>
  422. <style>
  423. .login-paddingtop {
  424. padding-top: 300upx;
  425. }
  426. .zai-box {
  427. height: 100vh;
  428. background-image: url(/static/desk-img/loginBg.png);
  429. background-size: cover;
  430. padding: 0 20upx;
  431. padding-top: 100upx;
  432. position: relative;
  433. }
  434. .zai-logo {
  435. width: 200upx;
  436. height: 150px;
  437. }
  438. .zai-title {
  439. margin-top: 20upx;
  440. font-size: 58upx;
  441. color: #000000;
  442. text-align: center;
  443. }
  444. .input-placeholder,
  445. .zai-input {
  446. color: #94afce;
  447. }
  448. .zai-btn {
  449. background: #ff65a3;
  450. color: #fff;
  451. border: 0;
  452. border-radius: 100upx;
  453. font-size: 36upx;
  454. }
  455. .zai-btn:after {
  456. border: 0;
  457. }
  458. /*按钮点击效果*/
  459. .zai-btn.button-hover {
  460. transform: translate(1upx, 1upx);
  461. }
  462. .IPSet {
  463. display: flex;
  464. flex-direction: column;
  465. }
  466. .text-style {
  467. margin: 20px;
  468. }
  469. </style>