login.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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: 'jinyuan',
  80. password: 'szjbd168',
  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. let that=this;
  157. this.mLogin(loginParams).then((res) => {
  158. this.loading=false;
  159. // console.log(res)
  160. if(res.data.state==200){
  161. // #ifdef APP-PLUS
  162. // this.saveClientId()
  163. // #endif
  164. // #ifndef APP-PLUS
  165. // console.log(this.$store)
  166. console.log(loginParams)
  167. let url="ibps/oauth2/v3/user/context?username="+loginParams.username
  168. //获取用户信息
  169. let userpara={username:loginParams.username};
  170. that.$http.post(url,userpara).then(res=>{
  171. if(res.data.state==200){
  172. console.log(res.data.data)
  173. uni.setStorageSync(USER_INFO,res.data.data);
  174. this.$tip.success('登录成功!')
  175. this.$Router.replaceAll({name:'index'})
  176. }else{
  177. if(res.data.state==500){
  178. this.$tip.alert(res.data.message);
  179. }else{
  180. this.$tip.alert(res.data.cause);
  181. }
  182. }
  183. //uni.setStorageSync(USER_INFO,userInfo);
  184. }).catch((err) => {
  185. let msg = err.data.message || "请求出现错误,请稍后再试"
  186. console.log(msg)
  187. this.loading=false;
  188. this.$tip.alert(msg);
  189. }).finally(()=>{
  190. this.loading=false;
  191. })
  192. // #endif
  193. }else {
  194. //console.log(res.data.message)
  195. if(res.data.state==500){
  196. this.$tip.alert(res.data.message);
  197. }else{
  198. this.$tip.alert(res.data.cause);
  199. }
  200. }
  201. }).catch((err) => {
  202. let msg = err.data.message || "请求出现错误,请稍后再试"
  203. console.log(msg)
  204. this.loading=false;
  205. this.$tip.alert(msg);
  206. }).finally(()=>{
  207. this.loading=false;
  208. })
  209. },
  210. zhuce(){
  211. this.$Router.push({name: "zhuce"})
  212. },
  213. saveClientId(){
  214. var info = plus.push.getClientInfo();
  215. var cid = info.clientid;
  216. this.$http.get("/sys/user/saveClientId",{params:{clientId:cid}}).then(res=>{
  217. console.log("res::saveClientId>",res)
  218. this.$tip.success('登录成功!')
  219. this.$Router.replaceAll({name:'index'})
  220. })
  221. },
  222. changePassword() {
  223. this.showPassword = !this.showPassword;
  224. },
  225. onSMSSend() {
  226. let smsParams = {};
  227. smsParams.phone=this.phoneNo;
  228. smsParams.smsmode="0";
  229. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  230. if(!smsParams.phone || smsParams.phone.length==0){
  231. this.$tip.toast('请输入手机号');
  232. return false
  233. }
  234. if(!checkPhone.test(smsParams.phone)){
  235. this.$tip.toast('请输入正确的手机号');
  236. return false
  237. }
  238. this.$http.post("/ibps/business/v3/mobile/sys/verification",smsParams).then(res=>{
  239. if(res.data.state==200){
  240. this.smsCountDown = 60;
  241. this.startSMSTimer();
  242. }else{
  243. this.smsCountDown = 0;
  244. this.$tip.toast(res.data.message);
  245. }
  246. });
  247. },
  248. startSMSTimer() {
  249. this.smsCountInterval = setInterval(() => {
  250. this.smsCountDown--;
  251. if (this.smsCountDown <= 0) {
  252. clearInterval(this.smsCountInterval);
  253. }
  254. }, 1000);
  255. },
  256. sig(sql){
  257. let rul = (sql.length + 9)*12*3+168
  258. let salt ="JinYuanXinTong"
  259. return md5(rul+''+salt)
  260. },
  261. onSMSLogin() {
  262. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  263. if(!this.phoneNo || this.phoneNo.length==0){
  264. this.$tip.toast('请填写手机号');
  265. return;
  266. }
  267. if(!checkPhone.test(this.phoneNo)){
  268. this.$tip.toast('请输入正确的手机号');
  269. return false
  270. }
  271. if(!this.smsCode || this.smsCode.length==0){
  272. this.$tip.toast('请填短信验证码');
  273. return;
  274. }
  275. let loginParams = {
  276. mobile:this.phoneNo,
  277. captcha:this.smsCode
  278. };
  279. this.PhoneLogin(loginParams).then((res) => {
  280. //console.log(this.$store)
  281. console.log("res====》",res)
  282. if(res.data.state==200){
  283. this.$tip.success('登录成功!')
  284. this.$Router.replaceAll({name:'index'})
  285. }else if(res.data.state==500) {
  286. this.$tip.error(res.data.message);
  287. }
  288. else{
  289. this.$tip.error(res.data.message);
  290. }
  291. }).catch((err) => {
  292. let msg = ((err.response || {}).data || {}).message || err.data.message || "请求出现错误,请稍后再试"
  293. this.$tip.error(msg);
  294. });
  295. },
  296. loginSuccess() {
  297. // 登陆成功,重定向到主页
  298. this.$Router.replace({name:'index'})
  299. },
  300. requestFailed(err) {
  301. this.$message.warning("登录失败")
  302. },
  303. },
  304. beforeDestroy() {
  305. if (this.smsCountInterval) {
  306. clearInterval(this.smsCountInterval);
  307. }
  308. },
  309. }
  310. </script>
  311. <style>
  312. .login-paddingtop {
  313. padding-top: 100upx;
  314. }
  315. .zai-box {
  316. padding: 0 20upx;
  317. padding-top: 100upx;
  318. position: relative;
  319. }
  320. .zai-logo {
  321. width: 200upx;
  322. height: 150px;
  323. }
  324. .zai-title {
  325. font-size: 58upx;
  326. color: #000000;
  327. text-align: center;
  328. }
  329. .input-placeholder, .zai-input {
  330. color: #94afce;
  331. }
  332. .zai-label {
  333. padding: 60upx 0;
  334. text-align: center;
  335. font-size: 30upx;
  336. color: #a7b6d0;
  337. }
  338. .zai-btn {
  339. background: #ff65a3;
  340. color: #fff;
  341. border: 0;
  342. border-radius: 100upx;
  343. font-size: 36upx;
  344. }
  345. .zai-btn:after {
  346. border: 0;
  347. }
  348. /*按钮点击效果*/
  349. .zai-btn.button-hover {
  350. transform: translate(1upx, 1upx);
  351. }
  352. </style>