login.vue 9.4 KB

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