login.vue 10 KB

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