login.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. <template>
  2. <view class="zai-box">
  3. <scroll-view scroll-y class="page">
  4. <view class="text-center" :style="[{ animation: 'show ' + 0.4 + 's 1' }]">
  5. <image src="/static/desk-img/logo.png" mode='aspectFit' class="zai-logo "></image>
  6. </view>
  7. <view class="text-center" :style="[{ animation: 'show ' + 0.4 + 's 1' }]">
  8. <!-- <u-link class="zai-title2 text-shadow " href="http://localhost:8080?ticket=234" >切换单点登录</u-link> -->
  9. <view class="zai-title2 text-shadow " @click="changeloginType">切换单点登录</view>
  10. </view>
  11. <view class="box padding-lr-xl login-paddingtop" :style="[{ animation: 'show ' + 0.6 + 's 1' }]">
  12. <block>
  13. <view class="cu-form-group margin-top shadow-warp" :class="[shape == 'round' ? 'round' : '']">
  14. <view class="title"><text class="cuIcon-people margin-right-xs"></text>账号:</view>
  15. <input placeholder="请输入账号" name="input" v-model="userName"></input>
  16. </view>
  17. <view class="cu-form-group margin-top shadow-warp" :class="[shape == 'round' ? 'round' : '']">
  18. <view class="title"><text class="cuIcon-lock margin-right-xs"></text>密码:</view>
  19. <input class="uni-input" placeholder="请输入密码" :password="!showPassword" v-model="password" />
  20. <view class="action text-lg">
  21. <text :class="[showPassword ? 'cuIcon-attention' : 'cuIcon-attentionforbid']"
  22. @click="changePassword"></text>
  23. </view>
  24. </view>
  25. <view class="padding text-center margin-top">
  26. <button class="cu-btn bg-blue lg margin-right shadow" :loading="loading"
  27. :class="[shape == 'round' ? 'round' : '']" @tap="onLogin"><text space="emsp">{{ loading ? "登录中..." :
  28. "登录" }}</text>
  29. </button>
  30. </view>
  31. </block>
  32. <!-- #ifdef APP-PLUS -->
  33. <view class="padding flex flex-direction text-center">
  34. 当前版本:{{ version }}
  35. </view>
  36. <!-- #endif -->
  37. </view>
  38. </scroll-view>
  39. <!-- 登录加载弹窗 -->
  40. <view class="cu-load load-modal" v-if="loading">
  41. <!-- <view class="cuIcon-emojifill text-orange"></view> -->
  42. <image src="/static/desk-img/144.png" mode="aspectFit" class="round"></image>
  43. <view class="gray-text">登录中...</view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import { ACCESS_TOKEN, USER_NAME, USER_INFO } from "@/common/util/constants";
  49. import { mapActions } from "vuex";
  50. import configService from "@/common/service/config.service.js";
  51. import {AesEncryption, getLoginCipher} from "@/common/util/cipher.js";
  52. //import FlvJs from "flv.js";
  53. import api from "@/api/api";
  54. export default {
  55. data() {
  56. return {
  57. shape: "", //round 圆形
  58. loading: false,
  59. userName: "",
  60. password: "",
  61. phoneNo: "",
  62. smsCode: "",
  63. showPassword: false, //是否显示明文
  64. smsCountDown: 0,
  65. smsCountInterval: null,
  66. toggleDelay: false,
  67. version: "",
  68. //第三方登录相关信息
  69. thirdType: "",
  70. thirdLoginInfo: "",
  71. thirdLoginState: false,
  72. bindingPhoneModal: false,
  73. thirdUserUuid: "",
  74. };
  75. },
  76. onLoad: function (option) {
  77. console.log("=======option.ticket======"+JSON.stringify(option.ticket));
  78. this.loginCas(option.ticket)
  79. // #ifdef APP-PLUS
  80. var that = this;
  81. plus.runtime.getProperty(plus.runtime.appid, function (wgtinfo) {
  82. that.version = wgtinfo.version;
  83. });
  84. // #endif
  85. },
  86. computed: {
  87. isSendSMSEnable() {
  88. return this.smsCountDown <= 0 && this.phoneNo.length > 4;
  89. },
  90. getSendBtnText() {
  91. if (this.smsCountDown > 0) {
  92. return this.smsCountDown + "秒后发送";
  93. } else {
  94. return "发送验证码";
  95. }
  96. },
  97. canSMSLogin() {
  98. return this.userName.length > 4 && this.smsCode.length > 4;
  99. },
  100. canPwdLogin() {
  101. return this.userName.length > 4 && this.password.length > 4;
  102. },
  103. },
  104. methods: {
  105. ...mapActions(["mLogin", "PhoneLogin", "ThirdLogin"]),
  106. // 判断是否在APP环境中
  107. isApp() {
  108. return typeof plus !== "undefined";
  109. },
  110. onLogin: function () {
  111. if (!this.userName || this.userName.length == 0) {
  112. this.$tip.toast("请填写用户名");
  113. return;
  114. }
  115. if (!this.password || this.password.length == 0) {
  116. this.$tip.toast("请填写密码");
  117. return;
  118. }
  119. let loginParams = {
  120. username: this.userName,
  121. password: this.password,
  122. };
  123. // 加密
  124. const loginCipher = getLoginCipher()
  125. const encryption = new AesEncryption({ key: loginCipher.key, iv: loginCipher.iv });
  126. loginParams.password = encryption.encryptByAES(loginParams.password)
  127. this.loading = true;
  128. this.mLogin(loginParams)
  129. .then((res) => {
  130. this.loading = false;
  131. if (res.data.success) {
  132. if (this.isApp()) {
  133. // console.log('当前是APP环境');
  134. this.saveClientId();
  135. } else {
  136. this.getPermissionList();
  137. }
  138. // #ifdef APP-PLUS
  139. // #endif
  140. // #ifndef APP-PLUS
  141. // #endif
  142. } else {
  143. this.$tip.alert(res.data.message);
  144. }
  145. })
  146. .catch((err) => {
  147. let msg = err.data.message || "请求出现错误,请稍后再试";
  148. this.loading = false;
  149. this.$tip.alert(msg);
  150. })
  151. .finally(() => {
  152. this.loading = false;
  153. });
  154. },
  155. loginCas(value) {
  156. var than = this;
  157. // this.$tip.success(configService.apiUrl);
  158. var ser = configService.apiUrl;
  159. ser = ser.replace(9999, 8092);
  160. // this.$tip.success(ser);
  161. new Promise((resolve, reject) => {
  162. api
  163. .validateCasLogin("", "?ticket=" + value + "&service=" + encodeURIComponent(ser))
  164. .then((response) => {
  165. // than.$tip.success("登录成功1");
  166. // if (response.data.code == 200) {
  167. // uni.setStorageSync(ACCESS_TOKEN, response.data.result.token);
  168. // } else {
  169. // }
  170. const result = response.data.result;
  171. const userInfo = result.userInfo;
  172. uni.setStorageSync(ACCESS_TOKEN, result.token);
  173. uni.setStorageSync(USER_INFO, userInfo);
  174. console.log("userInfo=" + userInfo);
  175. than.$store.commit("SET_TOKEN", result.token);
  176. console.log("result.token=" + result.token);
  177. than.$store.commit("SET_DICT", result.sysAllDictItems);
  178. than.$store.commit("SET_AVATAR", userInfo.avatar);
  179. than.$store.commit("SET_NAME", {
  180. username: userInfo.username,
  181. realname: userInfo.realname,
  182. });
  183. // than.$tip.success("loginCas=");
  184. than.getPermissionList();
  185. })
  186. .catch((error) => {
  187. debugger;
  188. console.log("catch===>response", error);
  189. // uni.navigateTo({
  190. // url: "/pages/home/home",
  191. // });
  192. });
  193. });
  194. },
  195. //获取权限菜单
  196. getPermissionList() {
  197. new Promise((resolve, reject) => {
  198. api
  199. .getPermission({})
  200. .then((response) => {
  201. console.log(response, "权限菜单----------------");
  202. if (response.statusCode == 200) {
  203. let data = response.data.result.menuApp;
  204. let dataBtn = response.data.result.appauth;
  205. uni.setStorageSync("menuPermission", data);
  206. uni.setStorageSync("btnPermission", dataBtn);
  207. this.$tip.success("登录成功!");
  208. uni.navigateTo({
  209. url: "/pages/index/index",
  210. });
  211. } else {
  212. reject(response);
  213. }
  214. })
  215. .catch((error) => {
  216. console.log("catch===>response", response);
  217. reject(error);
  218. });
  219. });
  220. },
  221. saveClientId() {
  222. var info = plus.push.getClientInfo();
  223. var cid = info.clientid;
  224. this.$http
  225. .get("/sys/user/saveClientId", { params: { clientId: cid } })
  226. .then((res) => {
  227. console.log("res::saveClientId>", res);
  228. //获取权限菜单
  229. this.getPermissionList();
  230. });
  231. },
  232. changePassword() {
  233. this.showPassword = !this.showPassword;
  234. },
  235. onSMSSend() {
  236. let smsParams = {};
  237. smsParams.mobile = this.phoneNo;
  238. smsParams.smsmode = "0";
  239. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  240. if (!smsParams.mobile || smsParams.mobile.length == 0) {
  241. this.$tip.toast("请输入手机号");
  242. return false;
  243. }
  244. if (!checkPhone.test(smsParams.mobile)) {
  245. this.$tip.toast("请输入正确的手机号");
  246. return false;
  247. }
  248. this.$http.post("/sys/sms", smsParams).then((res) => {
  249. if (res.data.success) {
  250. this.smsCountDown = 60;
  251. this.startSMSTimer();
  252. } else {
  253. this.smsCountDown = 0;
  254. this.$tip.toast(res.data.message);
  255. }
  256. });
  257. },
  258. startSMSTimer() {
  259. this.smsCountInterval = setInterval(() => {
  260. this.smsCountDown--;
  261. if (this.smsCountDown <= 0) {
  262. clearInterval(this.smsCountInterval);
  263. }
  264. }, 1000);
  265. },
  266. onSMSLogin() {
  267. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  268. if (!this.phoneNo || this.phoneNo.length == 0) {
  269. this.$tip.toast("请填写手机号");
  270. return;
  271. }
  272. if (!checkPhone.test(this.phoneNo)) {
  273. this.$tip.toast("请输入正确的手机号");
  274. return false;
  275. }
  276. if (!this.smsCode || this.smsCode.length == 0) {
  277. this.$tip.toast("请填短信验证码");
  278. return;
  279. }
  280. let loginParams = {
  281. mobile: this.phoneNo,
  282. captcha: this.smsCode,
  283. };
  284. this.PhoneLogin(loginParams)
  285. .then((res) => {
  286. console.log("res====》", res);
  287. if (res.data.success) {
  288. this.$tip.success("登录成功!");
  289. uni.navigateTo({
  290. url: "/pages/index/index",
  291. });
  292. } else {
  293. this.$tip.error(res.data.message);
  294. }
  295. })
  296. .catch((err) => {
  297. let msg =
  298. ((err.response || {}).data || {}).message ||
  299. err.data.message ||
  300. "请求出现错误,请稍后再试";
  301. this.$tip.error(msg);
  302. });
  303. },
  304. loginSuccess() {
  305. // 登陆成功,重定向到主页
  306. this.$Router.replace({ name: "index" });
  307. },
  308. requestFailed(err) {
  309. this.$message.warning("登录失败");
  310. },
  311. changeloginType() {
  312. console.log("changeloginType====");
  313. var tourl = configService.apiUrl;
  314. tourl = tourl.replace(9999, 8092);
  315. // this.$tip.success("tourl="+tourl);
  316. var rastourl =
  317. "https://id.shendong.com.cn/default" +
  318. "/login?service=" + tourl;
  319. // rastourl ="http://182.92.126.35:8092/?ticket=234";
  320. console.log("===========" + rastourl);
  321. this.openBrowser(rastourl);
  322. // window.location.href='/pages/index/index?ticket=123'
  323. // this.$router.push({ path: '/pages/index/index?ticket=123',query:"2w354" })
  324. },
  325. openBrowser(url) {
  326. // 使用uni.navigateTo打开内置浏览器
  327. console.log("----url---------------" + url);
  328. // this.$tip.success("url="+url);
  329. uni.navigateTo({
  330. url: "/pages/webview/webview?url=" + encodeURIComponent(url),
  331. });
  332. },
  333. },
  334. beforeDestroy() {
  335. if (this.smsCountInterval) {
  336. clearInterval(this.smsCountInterval);
  337. }
  338. },
  339. };
  340. </script>
  341. <style>
  342. .login-paddingtop {
  343. padding-top: 300upx;
  344. }
  345. .zai-box {
  346. height: 100vh;
  347. background-image: url(/static/desk-img/loginBg.png);
  348. background-size: cover;
  349. padding: 0 20upx;
  350. padding-top: 100upx;
  351. position: relative;
  352. }
  353. .zai-logo {
  354. width: 200upx;
  355. height: 150px;
  356. }
  357. .zai-title {
  358. margin-top: 20upx;
  359. font-size: 58upx;
  360. color: #000000;
  361. text-align: center;
  362. }
  363. .input-placeholder,
  364. .zai-input {
  365. color: #94afce;
  366. }
  367. .zai-btn {
  368. background: #ff65a3;
  369. color: #fff;
  370. border: 0;
  371. border-radius: 100upx;
  372. font-size: 36upx;
  373. }
  374. .zai-btn:after {
  375. border: 0;
  376. }
  377. /*按钮点击效果*/
  378. .zai-btn.button-hover {
  379. transform: translate(1upx, 1upx);
  380. }
  381. </style>