login.vue 10 KB

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