login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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="https://static.jeecg.com/upload/test/login4_1595818039175.png" mode='aspectFit' class="zai-logo "></image>
  6. <view class="zai-title text-shadow ">网上委托平台 </view>
  7. </view>
  8. <view class="box padding-lr-xl login-paddingtop" :style="[{animation: 'show ' + 0.6+ 's 1'}]">
  9. <block v-if="loginWay==1">
  10. <view class="cu-form-group margin-top shadow-warp" :class="[shape=='round'?'round':'']">
  11. <view class="title"><text class="cuIcon-people margin-right-xs"></text>账号:</view>
  12. <input placeholder="请输入账号" name="input" v-model="userName"></input>
  13. </view>
  14. <view class="cu-form-group margin-top shadow-warp" :class="[shape=='round'?'round':'']">
  15. <view class="title"><text class="cuIcon-lock margin-right-xs"></text>密码:</view>
  16. <input class="uni-input" placeholder="请输入密码" :password="!showPassword" v-model="password" />
  17. <view class="action text-lg">
  18. <text :class="[showPassword ? 'cuIcon-attention' : 'cuIcon-attentionforbid']" @click="changePassword"></text>
  19. </view>
  20. </view>
  21. <view @tap="zhuce()"> <text style="color: #E04B28;float: right; margin-right: 20rpx; " > 还未注册?请注册</text> </view>
  22. <view class="padding text-center margin-top">
  23. <button class="cu-btn bg-blue lg margin-right shadow" :loading="loading" :class="[shape=='round'?'round':'']"
  24. @tap="onLogin"><text space="emsp">{{loading ? "登录中...":" 登录 "}}</text>
  25. </button>
  26. <button class="cu-btn line-blue lg margin-left shadow" :loading="loading" :class="[shape=='round'?'round':'']"
  27. @tap="loginWay=3-loginWay">短信登录
  28. </button>
  29. </view>
  30. </block>
  31. <block v-else>
  32. <view class="cu-form-group margin-top shadow-warp" :class="[shape=='round'?'round':'']">
  33. <view class="title"><text class="cuIcon-mobile margin-right-xs"></text>手机号:</view>
  34. <input placeholder="请输入手机号" type="number" maxlength="11" v-model="phoneNo"></input>
  35. </view>
  36. <view class="cu-form-group margin-top shadow-warp" :class="[shape=='round'?'round':'']">
  37. <view class="title"><text class="cuIcon-lock margin-right-xs"></text>验证码:</view>
  38. <input class="uni-input" placeholder="请输入验证码" v-model="smsCode"/>
  39. <view class="action">
  40. <button class="cu-btn line-blue sm" :disabled="!isSendSMSEnable" @click="onSMSSend"> {{ getSendBtnText }}</button>
  41. </view>
  42. </view>
  43. <view @tap="zhuce()"> <text style="color: #E04B28;float: right; margin-right: 20rpx; " > 还未注册?请注册</text> </view>
  44. <view class="padding text-center margin-top">
  45. <button class="cu-btn bg-blue lg margin-right shadow" :loading="loading" :class="[shape=='round'?'round':'']"
  46. @tap="onSMSLogin"><text space="emsp">{{loading ? "登录中...":" 登录 "}}</text>
  47. </button>
  48. <button class="cu-btn line-blue lg margin-left shadow" :loading="loading" :class="[shape=='round'?'round':'']"
  49. @tap="loginWay=1">账户登录
  50. </button>
  51. </view>
  52. </block>
  53. <!-- #ifdef APP-PLUS -->
  54. <view class="padding flex flex-direction text-center">
  55. 当前版本:{{version}}
  56. </view>
  57. <!-- #endif -->
  58. </view>
  59. </scroll-view>
  60. <!-- 登录加载弹窗 -->
  61. <view class="cu-load load-modal" v-if="loading">
  62. <!-- <view class="cuIcon-emojifill text-orange"></view> -->
  63. <!-- <image src="https://static.jeecg.com/upload/test/login4_1595818039175.png" mode="aspectFit" class="round"></image>
  64. -->
  65. <view class="gray-text">登录中...</view>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. import { ACCESS_TOKEN,USER_NAME,USER_INFO } from "@/common/util/constants"
  71. import { mapActions } from "vuex"
  72. import configService from '@/common/service/config.service.js';
  73. import md5 from "@/common/util/md5.js"
  74. export default {
  75. data() {
  76. return {
  77. shape:'',//round 圆形
  78. loading: false,
  79. userName: '邓进源',
  80. password: '123456',
  81. phoneNo: '',
  82. smsCode: '',
  83. showPassword: false, //是否显示明文
  84. loginWay: 1, //1: 账密,2:验证码
  85. smsCountDown: 0,
  86. smsCountInterval: null,
  87. toggleDelay: false,
  88. version:'',
  89. //第三方登录相关信息
  90. thirdType:"",
  91. thirdLoginInfo:"",
  92. thirdLoginState:false,
  93. bindingPhoneModal:false,
  94. thirdUserUuid:'',
  95. url: {
  96. bindingThirdPhone: '/sys/thirdLogin/bindingThirdPhone'
  97. }
  98. };
  99. },
  100. onLoad:function(){
  101. console.log("登录页加载")
  102. // #ifdef APP-PLUS
  103. var that=this
  104. plus.runtime.getProperty( plus.runtime.appid, function ( wgtinfo ) {
  105. that.version=wgtinfo.version
  106. });
  107. // #endif
  108. },
  109. computed: {
  110. isSendSMSEnable() {
  111. return this.smsCountDown <= 0 && this.phoneNo.length > 4;
  112. },
  113. getSendBtnText() {
  114. if (this.smsCountDown > 0) {
  115. return this.smsCountDown + '秒后发送';
  116. } else {
  117. return '发送验证码';
  118. }
  119. },
  120. canSMSLogin() {
  121. return this.userName.length > 4 && this.smsCode.length > 4;
  122. },
  123. canPwdLogin() {
  124. return this.userName.length > 4 && this.password.length > 4;
  125. },
  126. },
  127. methods: {
  128. ...mapActions([ "mLogin","PhoneLogin","mSign", "ThirdLogin" ]),
  129. onLogin: function (){
  130. //请求系统接口demo
  131. /* let data="select * from t_sysjtsjpz where jian_ce_dui_xiang = '金属零件' and shi_fou_shan_chu_ = '0'";
  132. data='{"sql":"'+data+'"}'
  133. let md5 =this.sig(data) //加密, 获取md5密文
  134. let requestData = data.slice(0,1)+'"sig":"'+md5+'",'+data.slice(1) //结果拼接
  135. this.$http.post("/ibps/business/v3/sys/universal/inputSqlSelectData",requestData).then(res=>{
  136. }); */
  137. if(!this.userName || this.userName.length==0){
  138. this.$tip.toast('请填写用户名');
  139. return;
  140. }
  141. if(!this.password || this.password.length==0){
  142. this.$tip.toast('请填写密码');
  143. return;
  144. }
  145. let loginParams = {
  146. username:this.userName,
  147. password:this.password
  148. }
  149. this.loading=true;
  150. //请求后台登录
  151. //this.saveClientId()
  152. //this.$Router.replaceAll({name:'index'})
  153. //this.$Router.push({name: 'index'})
  154. //this.$tip.success('登录成功!')
  155. //return
  156. this.mLogin(loginParams).then((res) => {
  157. this.loading=false;
  158. // console.log(res)
  159. if(res.data.state==200){
  160. // #ifdef APP-PLUS
  161. // this.saveClientId()
  162. // #endif
  163. // #ifndef APP-PLUS
  164. // console.log(this.$store)
  165. this.$tip.success('登录成功!')
  166. this.$Router.replaceAll({name:'index'})
  167. // #endif
  168. }else {
  169. //console.log(res.data.message)
  170. if(res.data.state==500){
  171. this.$tip.alert(res.data.message);
  172. }else{
  173. this.$tip.alert(res.data.cause);
  174. }
  175. }
  176. }).catch((err) => {
  177. let msg = err.data.message || "请求出现错误,请稍后再试"
  178. console.log(msg)
  179. this.loading=false;
  180. this.$tip.alert(msg);
  181. }).finally(()=>{
  182. this.loading=false;
  183. })
  184. },
  185. zhuce(){
  186. this.$Router.push({name: "zhuce"})
  187. },
  188. saveClientId(){
  189. var info = plus.push.getClientInfo();
  190. var cid = info.clientid;
  191. this.$http.get("/sys/user/saveClientId",{params:{clientId:cid}}).then(res=>{
  192. console.log("res::saveClientId>",res)
  193. this.$tip.success('登录成功!')
  194. this.$Router.replaceAll({name:'index'})
  195. })
  196. },
  197. changePassword() {
  198. this.showPassword = !this.showPassword;
  199. },
  200. onSMSSend() {
  201. let smsParams = {};
  202. smsParams.phone=this.phoneNo;
  203. smsParams.smsmode="0";
  204. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  205. if(!smsParams.phone || smsParams.phone.length==0){
  206. this.$tip.toast('请输入手机号');
  207. return false
  208. }
  209. if(!checkPhone.test(smsParams.phone)){
  210. this.$tip.toast('请输入正确的手机号');
  211. return false
  212. }
  213. this.$http.post("/ibps/business/v3/mobile/sys/verification",smsParams).then(res=>{
  214. if(res.data.state==200){
  215. this.smsCountDown = 60;
  216. this.startSMSTimer();
  217. }else{
  218. this.smsCountDown = 0;
  219. this.$tip.toast(res.data.message);
  220. }
  221. });
  222. },
  223. startSMSTimer() {
  224. this.smsCountInterval = setInterval(() => {
  225. this.smsCountDown--;
  226. if (this.smsCountDown <= 0) {
  227. clearInterval(this.smsCountInterval);
  228. }
  229. }, 1000);
  230. },
  231. sig(sql){
  232. let rul = (sql.length + 9)*12*3+168
  233. let salt ="JinYuanXinTong"
  234. return md5(rul+''+salt)
  235. },
  236. onSMSLogin() {
  237. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  238. if(!this.phoneNo || this.phoneNo.length==0){
  239. this.$tip.toast('请填写手机号');
  240. return;
  241. }
  242. if(!checkPhone.test(this.phoneNo)){
  243. this.$tip.toast('请输入正确的手机号');
  244. return false
  245. }
  246. if(!this.smsCode || this.smsCode.length==0){
  247. this.$tip.toast('请填短信验证码');
  248. return;
  249. }
  250. let loginParams = {
  251. mobile:this.phoneNo,
  252. captcha:this.smsCode
  253. };
  254. this.PhoneLogin(loginParams).then((res) => {
  255. //console.log(this.$store)
  256. console.log("res====》",res)
  257. if(res.data.state==200){
  258. this.$tip.success('登录成功!')
  259. this.$Router.replaceAll({name:'index'})
  260. }else if(res.data.state==500) {
  261. this.$tip.error(res.data.message);
  262. }
  263. else{
  264. this.$tip.error(res.data.message);
  265. }
  266. }).catch((err) => {
  267. let msg = ((err.response || {}).data || {}).message || err.data.message || "请求出现错误,请稍后再试"
  268. this.$tip.error(msg);
  269. });
  270. },
  271. loginSuccess() {
  272. // 登陆成功,重定向到主页
  273. this.$Router.replace({name:'index'})
  274. },
  275. requestFailed(err) {
  276. this.$message.warning("登录失败")
  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. font-size: 58upx;
  301. color: #000000;
  302. text-align: center;
  303. }
  304. .input-placeholder, .zai-input {
  305. color: #94afce;
  306. }
  307. .zai-label {
  308. padding: 60upx 0;
  309. text-align: center;
  310. font-size: 30upx;
  311. color: #a7b6d0;
  312. }
  313. .zai-btn {
  314. background: #ff65a3;
  315. color: #fff;
  316. border: 0;
  317. border-radius: 100upx;
  318. font-size: 36upx;
  319. }
  320. .zai-btn:after {
  321. border: 0;
  322. }
  323. /*按钮点击效果*/
  324. .zai-btn.button-hover {
  325. transform: translate(1upx, 1upx);
  326. }
  327. </style>