index.vue 7.0 KB

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