login.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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://10.35.116.82:9999", code: 'qpj' },
  108. { label: "准东二矿", value: "http://172.19.7.101:9999", code: 'zdrk' },
  109. { label: "大海则煤矿", value: "http://172.16.53.16:9999", code: 'dhz' },
  110. { label: "大柳塔井", value: "http://10.248.135.10:9999", code: 'dlt' },
  111. { label: "活鸡兔井", value: "http://10.248.135.121:9999", code: 'hjt' },
  112. { label: "寸草塔二矿", value: "http://10.246.63.5:9999", code: 'cctr' },
  113. { label: "乌兰木伦", value: "http://10.246.183.35:9999", code: 'wlml' },
  114. { label: "哈拉沟煤矿", value: "http://10.248.223.12:9999", code: 'hlg' },
  115. { label: "布尔台", value: "http://10.246.95.4:9999", code: 'brt' },
  116. { label: "上湾", value: "http://10.246.167.205:9999", code: 'sw' },
  117. { label: "锦界", value: "http://10.248.151.42:9999", code: 'jj' },
  118. { label: "补连塔", value: "http://10.246.175.16:9999", code: 'blt' },
  119. { label: "寸草塔", value: "http://10.246.23.171:9999", code: 'cct' },
  120. { label: "柳塔", value: "http://10.246.87.121:9999", code: 'lt' },
  121. { label: "石圪台", value: "http://10.246.191.13:9999", code: 'sgt' },
  122. { label: "榆家梁", value: "http://10.248.143.211:9999", code: 'yjl' },
  123. { label: "开发", value: "http://182.92.126.35:9999", code: 'kf' },
  124. { label: "测试", value: "http://182.92.126.35:9998", code: 'cs' },
  125. { label: "特拉布拉", value: "http://10.7.0.19:9999", code: 'lblt' },
  126. ],
  127. ],
  128. };
  129. },
  130. onLoad: function (option) {
  131. console.log("=======option.ticket======" + JSON.stringify(option.ticket));
  132. this.loginCas(option.ticket);
  133. // #ifdef APP-PLUS
  134. var that = this;
  135. plus.runtime.getProperty(plus.runtime.appid, function (wgtinfo) {
  136. that.version = wgtinfo.version;
  137. });
  138. // #endif
  139. },
  140. computed: {
  141. isSendSMSEnable() {
  142. return this.smsCountDown <= 0 && this.phoneNo.length > 4;
  143. },
  144. getSendBtnText() {
  145. if (this.smsCountDown > 0) {
  146. return this.smsCountDown + "秒后发送";
  147. } else {
  148. return "发送验证码";
  149. }
  150. },
  151. canSMSLogin() {
  152. return this.userName.length > 4 && this.smsCode.length > 4;
  153. },
  154. canPwdLogin() {
  155. return this.userName.length > 4 && this.password.length > 4;
  156. },
  157. },
  158. methods: {
  159. ...mapActions(["mLogin", "PhoneLogin", "ThirdLogin"]),
  160. // 判断是否在APP环境中
  161. isApp() {
  162. return typeof plus !== "undefined";
  163. },
  164. onLogin: function () {
  165. if (!this.userName || this.userName.length == 0) {
  166. this.$tip.toast("请填写用户名");
  167. return;
  168. }
  169. if (!this.password || this.password.length == 0) {
  170. this.$tip.toast("请填写密码");
  171. return;
  172. }
  173. let loginParams = {
  174. username: this.userName,
  175. password: this.password,
  176. clientId: uni.getStorageSync('push_cid')
  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. console.log(configService, "changeloginType====");
  376. var tourl = configService.apiUrl;
  377. tourl = tourl.replace(9999, 8092);
  378. // this.$tip.success("tourl="+tourl);
  379. var rastourl =
  380. "https://id.shendong.com.cn/default" + "/login?service=" + tourl;
  381. // rastourl ="http://182.92.126.35:8092/?ticket=234";
  382. console.log("===========" + rastourl);
  383. this.openBrowser(rastourl);
  384. // window.location.href='/pages/index/index?ticket=123'
  385. // this.$router.push({ path: '/pages/index/index?ticket=123',query:"2w354" })
  386. },
  387. openBrowser(url) {
  388. // 使用uni.navigateTo打开内置浏览器
  389. console.log("----url---------------" + url);
  390. // this.$tip.success("url="+url);
  391. uni.navigateTo({
  392. url: "/pages/webview/webview?url=" + encodeURIComponent(url),
  393. });
  394. },
  395. setIp() {
  396. console.log("点击成功");
  397. this.ipShow = !this.ipShow;
  398. },
  399. changeIP() {
  400. this.ipShow1 = true;
  401. },
  402. selectIpAddr(e) {
  403. this.ipShow1 = false;
  404. const fullURL = e.value[0].value;
  405. this.IPSet = e.value[0].label;
  406. const apiCode = e.value[0].code
  407. configService.apiUrl = fullURL;
  408. uni.setStorageSync("apiUrl", configService.apiUrl);
  409. uni.setStorageSync("apiCode", apiCode);
  410. setTimeout(() => {
  411. uni.getStorageSync("apiUrl");
  412. }, 100);
  413. uni.navigateTo({ url: "/pages/login/login" });
  414. },
  415. },
  416. beforeDestroy() {
  417. if (this.smsCountInterval) {
  418. clearInterval(this.smsCountInterval);
  419. }
  420. },
  421. };
  422. </script>
  423. <style>
  424. .login-paddingtop {
  425. padding-top: 300upx;
  426. }
  427. .zai-box {
  428. height: 100vh;
  429. background-image: url(/static/desk-img/loginBg.png);
  430. background-size: cover;
  431. padding: 0 20upx;
  432. padding-top: 100upx;
  433. position: relative;
  434. }
  435. .zai-logo {
  436. width: 200upx;
  437. height: 150px;
  438. }
  439. .zai-title {
  440. margin-top: 20upx;
  441. font-size: 58upx;
  442. color: #000000;
  443. text-align: center;
  444. }
  445. .input-placeholder,
  446. .zai-input {
  447. color: #94afce;
  448. }
  449. .zai-btn {
  450. background: #ff65a3;
  451. color: #fff;
  452. border: 0;
  453. border-radius: 100upx;
  454. font-size: 36upx;
  455. }
  456. .zai-btn:after {
  457. border: 0;
  458. }
  459. /*按钮点击效果*/
  460. .zai-btn.button-hover {
  461. transform: translate(1upx, 1upx);
  462. }
  463. .IPSet {
  464. display: flex;
  465. flex-direction: column;
  466. }
  467. .text-style {
  468. margin: 20px;
  469. }
  470. </style>