login.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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({
  126. key: loginCipher.key,
  127. iv: loginCipher.iv,
  128. });
  129. loginParams.password = encryption.encryptByAES(loginParams.password);
  130. this.loading = true;
  131. this.mLogin(loginParams)
  132. .then((res) => {
  133. this.loading = false;
  134. if (res.data.success) {
  135. if (this.isApp()) {
  136. // console.log('当前是APP环境');
  137. this.saveClientId();
  138. } else {
  139. this.getPermissionList();
  140. }
  141. // #ifdef APP-PLUS
  142. // #endif
  143. // #ifndef APP-PLUS
  144. // #endif
  145. } else {
  146. this.$tip.alert(res.data.message);
  147. }
  148. })
  149. .catch((err) => {
  150. let msg = err.data.message || "请求出现错误,请稍后再试";
  151. this.loading = false;
  152. this.$tip.alert(msg);
  153. })
  154. .finally(() => {
  155. this.loading = false;
  156. });
  157. },
  158. loginCas(value) {
  159. var than = this;
  160. // this.$tip.success(configService.apiUrl);
  161. var ser = configService.apiUrl;
  162. ser = ser.replace(9999, 8092);
  163. // this.$tip.success(ser);
  164. new Promise((resolve, reject) => {
  165. api
  166. .validateCasLogin(
  167. "",
  168. "?ticket=" + value + "&service=" + encodeURIComponent(ser)
  169. )
  170. .then((response) => {
  171. // than.$tip.success("登录成功1");
  172. // if (response.data.code == 200) {
  173. // uni.setStorageSync(ACCESS_TOKEN, response.data.result.token);
  174. // } else {
  175. // }
  176. const result = response.data.result;
  177. const userInfo = result.userInfo;
  178. uni.setStorageSync(ACCESS_TOKEN, result.token);
  179. uni.setStorageSync(USER_INFO, userInfo);
  180. console.log("userInfo=" + userInfo);
  181. than.$store.commit("SET_TOKEN", result.token);
  182. console.log("result.token=" + result.token);
  183. than.$store.commit("SET_DICT", result.sysAllDictItems);
  184. than.$store.commit("SET_AVATAR", userInfo.avatar);
  185. than.$store.commit("SET_NAME", {
  186. username: userInfo.username,
  187. realname: userInfo.realname,
  188. });
  189. // than.$tip.success("loginCas=");
  190. than.getPermissionList();
  191. })
  192. .catch((error) => {
  193. debugger;
  194. console.log("catch===>response", error);
  195. // uni.navigateTo({
  196. // url: "/pages/home/home",
  197. // });
  198. });
  199. });
  200. },
  201. //获取权限菜单
  202. getPermissionList() {
  203. new Promise((resolve, reject) => {
  204. api
  205. .getPermission({})
  206. .then((response) => {
  207. console.log(response, "权限菜单----------------");
  208. if (response.statusCode == 200) {
  209. let data = response.data.result.menuApp;
  210. let dataBtn = response.data.result.appauth;
  211. uni.setStorageSync("menuPermission", data);
  212. uni.setStorageSync("btnPermission", dataBtn);
  213. this.$tip.success("登录成功!");
  214. uni.navigateTo({
  215. url: "/pages/index/index",
  216. });
  217. } else {
  218. reject(response);
  219. }
  220. })
  221. .catch((error) => {
  222. console.log("catch===>response", response);
  223. reject(error);
  224. });
  225. });
  226. },
  227. saveClientId() {
  228. var info = plus.push.getClientInfo();
  229. var cid = info.clientid;
  230. this.$http
  231. .get("/sys/user/saveClientId", { params: { clientId: cid } })
  232. .then((res) => {
  233. console.log("res::saveClientId>", res);
  234. //获取权限菜单
  235. this.getPermissionList();
  236. });
  237. },
  238. changePassword() {
  239. this.showPassword = !this.showPassword;
  240. },
  241. onSMSSend() {
  242. let smsParams = {};
  243. smsParams.mobile = this.phoneNo;
  244. smsParams.smsmode = "0";
  245. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  246. if (!smsParams.mobile || smsParams.mobile.length == 0) {
  247. this.$tip.toast("请输入手机号");
  248. return false;
  249. }
  250. if (!checkPhone.test(smsParams.mobile)) {
  251. this.$tip.toast("请输入正确的手机号");
  252. return false;
  253. }
  254. this.$http.post("/sys/sms", smsParams).then((res) => {
  255. if (res.data.success) {
  256. this.smsCountDown = 60;
  257. this.startSMSTimer();
  258. } else {
  259. this.smsCountDown = 0;
  260. this.$tip.toast(res.data.message);
  261. }
  262. });
  263. },
  264. startSMSTimer() {
  265. this.smsCountInterval = setInterval(() => {
  266. this.smsCountDown--;
  267. if (this.smsCountDown <= 0) {
  268. clearInterval(this.smsCountInterval);
  269. }
  270. }, 1000);
  271. },
  272. onSMSLogin() {
  273. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  274. if (!this.phoneNo || this.phoneNo.length == 0) {
  275. this.$tip.toast("请填写手机号");
  276. return;
  277. }
  278. if (!checkPhone.test(this.phoneNo)) {
  279. this.$tip.toast("请输入正确的手机号");
  280. return false;
  281. }
  282. if (!this.smsCode || this.smsCode.length == 0) {
  283. this.$tip.toast("请填短信验证码");
  284. return;
  285. }
  286. let loginParams = {
  287. mobile: this.phoneNo,
  288. captcha: this.smsCode,
  289. };
  290. this.PhoneLogin(loginParams)
  291. .then((res) => {
  292. console.log("res====》", res);
  293. if (res.data.success) {
  294. this.$tip.success("登录成功!");
  295. uni.navigateTo({
  296. url: "/pages/inedx/inedx",
  297. });
  298. } else {
  299. this.$tip.error(res.data.message);
  300. }
  301. })
  302. .catch((err) => {
  303. let msg =
  304. ((err.response || {}).data || {}).message ||
  305. err.data.message ||
  306. "请求出现错误,请稍后再试";
  307. this.$tip.error(msg);
  308. });
  309. },
  310. loginSuccess() {
  311. // 登陆成功,重定向到主页
  312. this.$Router.replace({ name: "index" });
  313. },
  314. requestFailed(err) {
  315. this.$message.warning("登录失败");
  316. },
  317. changeloginType() {
  318. console.log("changeloginType====");
  319. var tourl = configService.apiUrl;
  320. tourl = tourl.replace(9999, 8092);
  321. // this.$tip.success("tourl="+tourl);
  322. var rastourl =
  323. "https://id.shendong.com.cn/default" + "/login?service=" + tourl;
  324. // rastourl ="http://182.92.126.35:8092/?ticket=234";
  325. console.log("===========" + rastourl);
  326. this.openBrowser(rastourl);
  327. // window.location.href='/pages/index/index?ticket=123'
  328. // this.$router.push({ path: '/pages/index/index?ticket=123',query:"2w354" })
  329. },
  330. openBrowser(url) {
  331. // 使用uni.navigateTo打开内置浏览器
  332. console.log("----url---------------" + url);
  333. // this.$tip.success("url="+url);
  334. uni.navigateTo({
  335. url: "/pages/webview/webview?url=" + encodeURIComponent(url),
  336. });
  337. },
  338. },
  339. beforeDestroy() {
  340. if (this.smsCountInterval) {
  341. clearInterval(this.smsCountInterval);
  342. }
  343. },
  344. };
  345. </script>
  346. <style>
  347. .login-paddingtop {
  348. padding-top: 300upx;
  349. }
  350. .zai-box {
  351. height: 100vh;
  352. background-image: url(/static/desk-img/loginBg.png);
  353. background-size: cover;
  354. padding: 0 20upx;
  355. padding-top: 100upx;
  356. position: relative;
  357. }
  358. .zai-logo {
  359. width: 200upx;
  360. height: 150px;
  361. }
  362. .zai-title {
  363. margin-top: 20upx;
  364. font-size: 58upx;
  365. color: #000000;
  366. text-align: center;
  367. }
  368. .input-placeholder,
  369. .zai-input {
  370. color: #94afce;
  371. }
  372. .zai-btn {
  373. background: #ff65a3;
  374. color: #fff;
  375. border: 0;
  376. border-radius: 100upx;
  377. font-size: 36upx;
  378. }
  379. .zai-btn:after {
  380. border: 0;
  381. }
  382. /*按钮点击效果*/
  383. .zai-btn.button-hover {
  384. transform: translate(1upx, 1upx);
  385. }
  386. </style>