login.vue 16 KB

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