login.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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 () {
  77. // #ifdef APP-PLUS
  78. var that = this;
  79. plus.runtime.getProperty(plus.runtime.appid, function (wgtinfo) {
  80. that.version = wgtinfo.version;
  81. });
  82. // #endif
  83. },
  84. computed: {
  85. isSendSMSEnable() {
  86. return this.smsCountDown <= 0 && this.phoneNo.length > 4;
  87. },
  88. getSendBtnText() {
  89. if (this.smsCountDown > 0) {
  90. return this.smsCountDown + "秒后发送";
  91. } else {
  92. return "发送验证码";
  93. }
  94. },
  95. canSMSLogin() {
  96. return this.userName.length > 4 && this.smsCode.length > 4;
  97. },
  98. canPwdLogin() {
  99. return this.userName.length > 4 && this.password.length > 4;
  100. },
  101. },
  102. methods: {
  103. ...mapActions(["mLogin", "PhoneLogin", "ThirdLogin"]),
  104. // 判断是否在APP环境中
  105. isApp() {
  106. return typeof plus !== "undefined";
  107. },
  108. onLogin: function () {
  109. if (!this.userName || this.userName.length == 0) {
  110. this.$tip.toast("请填写用户名");
  111. return;
  112. }
  113. if (!this.password || this.password.length == 0) {
  114. this.$tip.toast("请填写密码");
  115. return;
  116. }
  117. let loginParams = {
  118. username: this.userName,
  119. password: this.password,
  120. };
  121. // 加密
  122. const loginCipher = getLoginCipher()
  123. const encryption = new AesEncryption({ key: loginCipher.key, iv: loginCipher.iv });
  124. loginParams.password = encryption.encryptByAES(loginParams.password)
  125. this.loading = true;
  126. this.mLogin(loginParams)
  127. .then((res) => {
  128. this.loading = false;
  129. if (res.data.success) {
  130. if (this.isApp()) {
  131. // console.log('当前是APP环境');
  132. this.saveClientId();
  133. } else {
  134. this.getPermissionList();
  135. }
  136. // #ifdef APP-PLUS
  137. // #endif
  138. // #ifndef APP-PLUS
  139. // #endif
  140. } else {
  141. this.$tip.alert(res.data.message);
  142. }
  143. })
  144. .catch((err) => {
  145. let msg = err.data.message || "请求出现错误,请稍后再试";
  146. this.loading = false;
  147. this.$tip.alert(msg);
  148. })
  149. .finally(() => {
  150. this.loading = false;
  151. });
  152. },
  153. //获取权限菜单
  154. getPermissionList() {
  155. new Promise((resolve, reject) => {
  156. api
  157. .getPermission({})
  158. .then((response) => {
  159. console.log(response, "权限菜单----------------");
  160. if (response.statusCode == 200) {
  161. let data = response.data.result.menuApp;
  162. let dataBtn = response.data.result.appauth;
  163. uni.setStorageSync("menuPermission", data);
  164. uni.setStorageSync("btnPermission", dataBtn);
  165. this.$tip.success("登录成功!");
  166. uni.navigateTo({
  167. url: "/pages/index/index",
  168. });
  169. } else {
  170. reject(response);
  171. }
  172. })
  173. .catch((error) => {
  174. console.log("catch===>response", response);
  175. reject(error);
  176. });
  177. });
  178. },
  179. saveClientId() {
  180. var info = plus.push.getClientInfo();
  181. var cid = info.clientid;
  182. this.$http
  183. .get("/sys/user/saveClientId", { params: { clientId: cid } })
  184. .then((res) => {
  185. console.log("res::saveClientId>", res);
  186. //获取权限菜单
  187. this.getPermissionList();
  188. });
  189. },
  190. changePassword() {
  191. this.showPassword = !this.showPassword;
  192. },
  193. onSMSSend() {
  194. let smsParams = {};
  195. smsParams.mobile = this.phoneNo;
  196. smsParams.smsmode = "0";
  197. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  198. if (!smsParams.mobile || smsParams.mobile.length == 0) {
  199. this.$tip.toast("请输入手机号");
  200. return false;
  201. }
  202. if (!checkPhone.test(smsParams.mobile)) {
  203. this.$tip.toast("请输入正确的手机号");
  204. return false;
  205. }
  206. this.$http.post("/sys/sms", smsParams).then((res) => {
  207. if (res.data.success) {
  208. this.smsCountDown = 60;
  209. this.startSMSTimer();
  210. } else {
  211. this.smsCountDown = 0;
  212. this.$tip.toast(res.data.message);
  213. }
  214. });
  215. },
  216. startSMSTimer() {
  217. this.smsCountInterval = setInterval(() => {
  218. this.smsCountDown--;
  219. if (this.smsCountDown <= 0) {
  220. clearInterval(this.smsCountInterval);
  221. }
  222. }, 1000);
  223. },
  224. onSMSLogin() {
  225. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  226. if (!this.phoneNo || this.phoneNo.length == 0) {
  227. this.$tip.toast("请填写手机号");
  228. return;
  229. }
  230. if (!checkPhone.test(this.phoneNo)) {
  231. this.$tip.toast("请输入正确的手机号");
  232. return false;
  233. }
  234. if (!this.smsCode || this.smsCode.length == 0) {
  235. this.$tip.toast("请填短信验证码");
  236. return;
  237. }
  238. let loginParams = {
  239. mobile: this.phoneNo,
  240. captcha: this.smsCode,
  241. };
  242. this.PhoneLogin(loginParams)
  243. .then((res) => {
  244. console.log("res====》", res);
  245. if (res.data.success) {
  246. this.$tip.success("登录成功!");
  247. uni.navigateTo({
  248. url: "/pages/index/index",
  249. });
  250. } else {
  251. this.$tip.error(res.data.message);
  252. }
  253. })
  254. .catch((err) => {
  255. let msg =
  256. ((err.response || {}).data || {}).message ||
  257. err.data.message ||
  258. "请求出现错误,请稍后再试";
  259. this.$tip.error(msg);
  260. });
  261. },
  262. loginSuccess() {
  263. // 登陆成功,重定向到主页
  264. this.$Router.replace({ name: "index" });
  265. },
  266. requestFailed(err) {
  267. this.$message.warning("登录失败");
  268. },
  269. changeloginType() {
  270. console.log("changeloginType====");
  271. var tourl = configService.apiUrl;
  272. tourl = tourl.replace(9999, 8092);
  273. var rastourl =
  274. "https://id.shendong.com.cn/default" +
  275. "/login?service=" + tourl;
  276. console.log("===========" + rastourl);
  277. this.openBrowser(rastourl);
  278. // window.location.href='/pages/index/index?ticket=123'
  279. // this.$router.push({ path: '/pages/index/index?ticket=123',query:"2w354" })
  280. },
  281. openBrowser(url) {
  282. // 使用uni.navigateTo打开内置浏览器
  283. console.log("----url---------------" + url);
  284. uni.navigateTo({
  285. url: "/pages/webview/webview?url=" + encodeURIComponent(url),
  286. });
  287. },
  288. },
  289. beforeDestroy() {
  290. if (this.smsCountInterval) {
  291. clearInterval(this.smsCountInterval);
  292. }
  293. },
  294. };
  295. </script>
  296. <style>
  297. .login-paddingtop {
  298. padding-top: 300upx;
  299. }
  300. .zai-box {
  301. height: 100vh;
  302. background-image: url(/static/desk-img/loginBg.png);
  303. background-size: cover;
  304. padding: 0 20upx;
  305. padding-top: 100upx;
  306. position: relative;
  307. }
  308. .zai-logo {
  309. width: 200upx;
  310. height: 150px;
  311. }
  312. .zai-title {
  313. margin-top: 20upx;
  314. font-size: 58upx;
  315. color: #000000;
  316. text-align: center;
  317. }
  318. .input-placeholder,
  319. .zai-input {
  320. color: #94afce;
  321. }
  322. .zai-btn {
  323. background: #ff65a3;
  324. color: #fff;
  325. border: 0;
  326. border-radius: 100upx;
  327. font-size: 36upx;
  328. }
  329. .zai-btn:after {
  330. border: 0;
  331. }
  332. /*按钮点击效果*/
  333. .zai-btn.button-hover {
  334. transform: translate(1upx, 1upx);
  335. }
  336. </style>