login.vue 9.1 KB

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