login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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/144.png" mode='aspectFit' class="zai-logo "></image>
  6. <view class="zai-title text-shadow ">登 录</view>
  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. </view>
  47. </template>
  48. <script>
  49. import { ACCESS_TOKEN, USER_NAME, USER_INFO } from "@/common/util/constants";
  50. import { mapActions } from "vuex";
  51. import configService from "@/common/service/config.service.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, 8080);
  268. tourl =
  269. "https://id.shendong.com.cn/default" +
  270. "/login?service=" +
  271. "http://localhost:8080";
  272. console.log("===========" + tourl);
  273. if (process.env.VUE_APP_PLATFORM != "h5") {
  274. // plus.runtime.openURL('http://localhost:8080?ticket=12345')
  275. this.openBrowser("http://localhost:8080?ticket=12345");
  276. } else this.openBrowser("https://www.baidu.com");
  277. // window.location.href='/pages/index/index?ticket=123'
  278. // this.$router.push({ path: '/pages/index/index?ticket=123',query:"2w354" })
  279. },
  280. openBrowser(url) {
  281. // 使用uni.navigateTo打开内置浏览器
  282. console.log("----url---------------" + url);
  283. uni.navigateTo({
  284. url: "/pages/webview/webview?url=" + encodeURIComponent(url),
  285. });
  286. },
  287. },
  288. beforeDestroy() {
  289. if (this.smsCountInterval) {
  290. clearInterval(this.smsCountInterval);
  291. }
  292. },
  293. };
  294. </script>
  295. <style>
  296. .login-paddingtop {
  297. padding-top: 100upx;
  298. }
  299. .zai-box {
  300. padding: 0 20upx;
  301. padding-top: 100upx;
  302. position: relative;
  303. }
  304. .zai-logo {
  305. width: 200upx;
  306. height: 150px;
  307. }
  308. .zai-title {
  309. margin-top: 20upx;
  310. font-size: 58upx;
  311. color: #000000;
  312. text-align: center;
  313. }
  314. <<<<<<< HEAD .input-placeholder,
  315. .zai-input {
  316. color: #94afce;
  317. }
  318. =======.zai-title2 {
  319. margin-top: 20upx;
  320. font-size: 28upx;
  321. color: #000000;
  322. text-align: center;
  323. }
  324. .input-placeholder,
  325. .zai-input {
  326. color: #94afce;
  327. }
  328. >>>>>>>f9a901e3f950200c21f1645c7cafe558c314d958 .zai-label {
  329. padding: 60upx 0;
  330. text-align: center;
  331. font-size: 30upx;
  332. color: #a7b6d0;
  333. }
  334. .zai-btn {
  335. background: #ff65a3;
  336. color: #fff;
  337. border: 0;
  338. border-radius: 100upx;
  339. font-size: 36upx;
  340. }
  341. .zai-btn:after {
  342. border: 0;
  343. }
  344. /*按钮点击效果*/
  345. .zai-btn.button-hover {
  346. transform: translate(1upx, 1upx);
  347. }
  348. </style>