index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <template>
  2. <view>
  3. <view class="main">
  4. <view class="close" @click="goBack">
  5. <u-icon name="close" size="32" color="#101010"></u-icon>
  6. </view>
  7. <view class="logo">
  8. <img src="../../assets/img/logo.png" alt="">
  9. </view>
  10. <view class="name">
  11. 荆州市地方铁路有限公司
  12. </view>
  13. <view class="login">
  14. <view class="login-box">
  15. <view :class="['tel',telHighlight==true?'highlight':'']" >
  16. <view class="icon">
  17. <u-icon name="account-fill" size="40"></u-icon>
  18. </view>
  19. <view class="line">
  20. </view>
  21. <view class="tips">
  22. <u-input type="number"
  23. @focus="handleTelFocus" @blur="handleTelBlur"
  24. v-model="form.phone" placeholder="请填写系统预留手机号码" />
  25. </view>
  26. </view>
  27. <view :class="['pwd',pwdHighlight==true?'highlight':'']">
  28. <view class="icon">
  29. <u-icon name="chat-fill" size="40"></u-icon>
  30. </view>
  31. <view class="line">
  32. </view>
  33. <view class="tips">
  34. <view class="input">
  35. <u-input type="number" v-model="form.code"
  36. @focus="handlePwdFocus" @blur="handlePwdBlur"
  37. placeholder="请输入验证码" />
  38. </view>
  39. <view class="verification-code" @click="getCode" >{{codeTips}}</view>
  40. <u-verification-code :seconds="sendMsgSecond" ref="uCode" @change="codeChange" @end="end" @start="start">
  41. </u-verification-code>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="btn">
  47. <button
  48. :class="{
  49. 'login-btn':!(form.phone&&form.code)
  50. }" type="primary"
  51. @click="finish"
  52. >登录</button>
  53. </view>
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. import * as API from '@/apis/pagejs/user.js'
  59. import {
  60. checkPhone
  61. } from '@/apis/utils'
  62. export default {
  63. data() {
  64. return {
  65. form: {
  66. name: '',
  67. phone: '',
  68. code: '',
  69. },
  70. codeTips: '',
  71. isSendMsgIng: false,
  72. sendMsgSecond: 60 * 2,
  73. customStyle: {
  74. background: '#1677ff'
  75. },
  76. telHighlight:false,
  77. pwdHighlight:false
  78. }
  79. },
  80. onLoad(op) {
  81. // this.message = op.message;
  82. // this.backUrl = op.back;
  83. if (op.phone) {
  84. this.form.phone = op.phone;
  85. }
  86. },
  87. onReady() {
  88. this.query()
  89. },
  90. methods: {
  91. // 帐号框聚焦失焦
  92. handleTelFocus(){
  93. this.telHighlight=true
  94. },
  95. handleTelBlur(){
  96. this.telHighlight=false
  97. },
  98. // 密码框聚焦失焦
  99. handlePwdFocus(){
  100. this.pwdHighlight=true
  101. },
  102. handlePwdBlur(){
  103. this.pwdHighlight=false
  104. },
  105. goBack(){
  106. uni.redirectTo({
  107. url: '/'
  108. })
  109. },codeChange(text) {
  110. this.codeTips = text;
  111. },
  112. //倒计时
  113. end() {
  114. this.sendMsgSecond = 2 * 60;
  115. this.isSendMsgIng = false;
  116. },
  117. finish() {
  118. if (!this.carhelp.getOpenId()) {
  119. // uni.showToast({
  120. // title: "请使用“微信”访问本系统登录"
  121. // })
  122. // return
  123. }
  124. if (!this.form.phone) {
  125. uni.showToast({
  126. title: "请输入手机号"
  127. })
  128. return
  129. }
  130. if (!this.form.code) {
  131. uni.showToast({
  132. title: "请输入验证码"
  133. })
  134. return
  135. }
  136. uni.showLoading({
  137. title: "加载中",
  138. mask: true,
  139. })
  140. var headImg = "";
  141. var userInfo = this.carhelp.get("xpgj_wx_user_info")
  142. if (userInfo) {
  143. headImg = userInfo.headimgurl;
  144. }
  145. API.validateCode({
  146. verifyCode: this.form.code,
  147. telephone: this.form.phone,
  148. openId: this.carhelp.getOpenId(),
  149. headImg: headImg
  150. }).then((response) => {
  151. this.loginset(response)
  152. }).catch(error => {
  153. uni.showToast({
  154. title: error,
  155. icon: "none"
  156. })
  157. })
  158. },
  159. start() {
  160. if (!this.isSendMsgIng) {
  161. uni.showLoading({
  162. title: "加载中",
  163. mask: true,
  164. })
  165. API.getVerifyCode(this.form.phone).then((response) => {
  166. uni.hideLoading();
  167. this.carhelp.set("getvcodetime", new Date().getTime());
  168. if (!"") {
  169. //倒计时
  170. uni.showToast({
  171. title: "发送成功"
  172. })
  173. } else {
  174. uni.showToast({
  175. title: "您的验证码已经发送[5分钟有效],请勿重复点击"
  176. })
  177. }
  178. }).catch(error => {
  179. uni.showToast({
  180. title: error,
  181. icon: "none"
  182. })
  183. })
  184. }
  185. },
  186. // 获取验证码
  187. getCode() {
  188. if (this.$refs.uCode.canGetCode) {
  189. } else {
  190. uni.showToast({
  191. title: '倒计时结束后再发送',
  192. icon: "none"
  193. })
  194. return
  195. }
  196. var checkPhoneResult = checkPhone(this.form.phone);
  197. if (checkPhoneResult !== true) {
  198. uni.showToast({
  199. title: checkPhoneResult,
  200. })
  201. return;
  202. }
  203. this.$refs.uCode.start();
  204. },
  205. loginset(response){
  206. var token = response ? response.data.token : '';
  207. this.carhelp.setToken(token);
  208. this.carhelp.setPersonInfo(response.data.regUser);
  209. this.carhelp.setPersonInfoPlus(response.data)
  210. //this.gotoUrl("pages/user/index")
  211. uni.redirectTo({
  212. url: '/'
  213. })
  214. },
  215. query(){
  216. uni.showLoading({
  217. title: "加载中",
  218. mask: true,
  219. })
  220. API.findByOpenId({
  221. noerror:true,
  222. openId: this.carhelp.getOpenId(),
  223. }).then((response) => {
  224. this.loginset(response)
  225. }).catch(error => {
  226. uni.hideLoading();
  227. // if (!this.carhelp.getOpenId()) {
  228. // uni.showToast({
  229. // title: "请使用“微信”访问本系统登录"
  230. // })
  231. // return
  232. // }
  233. var time = this.carhelp.get("getvcodetime");
  234. if (time) {
  235. //this.$refs.uCode.start();
  236. var nowtime = new Date().getTime()
  237. var differ = (nowtime - time) / 1000
  238. if (differ < 2 * 60) {
  239. this.sendMsgSecond = 2 * 60 - parseInt(differ)
  240. this.isSendMsgIng = true;
  241. this.$refs.uCode.start();
  242. }
  243. }
  244. })
  245. }
  246. }
  247. }
  248. </script>
  249. <style lang="scss" scoped>
  250. page {
  251. background: url("../../assets/img/bgc.png");
  252. }
  253. .main {
  254. width: 100%;
  255. padding-top:240rpx;
  256. position: relative;
  257. .close{
  258. position: absolute;
  259. top: 24rpx;
  260. left: 24rpx;
  261. }
  262. .logo {
  263. display: flex;
  264. justify-content: center;
  265. }
  266. .name {
  267. color: rgba(16, 16, 16, 1);
  268. font-size: 40rDDpx;
  269. text-align: center;
  270. font-weight: bold;
  271. margin-top: 8rpx;
  272. }
  273. }
  274. .login-box {
  275. margin-top: 160rpx;
  276. .tel {
  277. /deep/.u-input {
  278. width: 400rpx;
  279. }
  280. }
  281. .line{
  282. width: 2rpx;
  283. height: 40rpx;
  284. background-color: #C1CCDF;
  285. position: absolute;
  286. top: 20rpx;
  287. left: 70rpx;
  288. }
  289. .tel,
  290. .pwd {
  291. position: relative;
  292. display: flex;
  293. width: 74.4%;
  294. height: 80rpx;
  295. line-height: 80rpx;
  296. color: rgba(183, 172, 172, 1);
  297. margin: auto;
  298. margin-bottom: 36rpx;
  299. border: 1px solid rgba(193, 204, 223, 1);
  300. border-radius: 8px;
  301. /deep/.u-input__input{
  302. font-size: 32rpx;
  303. }
  304. .icon {
  305. width: 14%;
  306. text-align: center;
  307. color: #B0B8C8;
  308. img {
  309. vertical-align: middle;
  310. }
  311. }
  312. .tips {
  313. text-indent: 16rpx;
  314. padding-right: 16rpx;
  315. display: flex;
  316. justify-content: space-between;
  317. /deep/uni-input {
  318. height: 80rpx !important;
  319. line-height: 80rpx !important;
  320. }
  321. .input {
  322. width: 50%;
  323. }
  324. }
  325. // 验证码
  326. .verification-code {
  327. color: #1F4A99;
  328. line-height: 80rpx;
  329. }
  330. }
  331. .highlight {
  332. border: 1px solid rgba(31, 74, 153, 1);
  333. box-shadow: 0px 0px 8rpx 0px rgba(0, 90, 217, 50);
  334. /deep/.u-input__input{
  335. color: rgba(0, 90, 217, 1);
  336. }
  337. .icon{
  338. color: #1F4A99;
  339. }
  340. .line{
  341. background-color: #005AD9;
  342. }
  343. }
  344. }
  345. .btn{
  346. width: 100%;
  347. margin-top: 120rpx;
  348. uni-button{
  349. margin:0 96rpx;
  350. height: 80rpx;
  351. border-radius: 8px;
  352. background-color: rgba(31, 74, 153, 1);
  353. color: rgba(255, 255, 255, 1);
  354. font-size: 16px;
  355. }
  356. }
  357. </style>