login.vue 14 KB

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