c1847b446e0526feeb7ef9ccf84eb6ce9575489c.svn-base 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <div class="login">
  3. 操作日志
  4. <!-- 手机号 -->
  5. <!-- <InputGroup
  6. v-model="phone"
  7. type="number"
  8. placeholder="手机号"
  9. :btn-title="btnTitle"
  10. :disabled="disabled"
  11. :error="errors.phone"
  12. @btnClick="getVerifyCode"
  13. /> -->
  14. <!-- 输入验证码 -->
  15. <!-- <InputGroup
  16. v-model="verifyCode"
  17. type="number"
  18. placeholder="验证码"
  19. :error="errors.code"
  20. /> -->
  21. <!-- 登录按钮 -->
  22. <!-- <div class="login_btn">
  23. <button :disabled="isClick" @click="handleLogin">登录</button>
  24. </div> -->
  25. </div>
  26. </template>
  27. <script>
  28. import InputGroup from '@/components/InputGroup' // 引入封装的组件
  29. export default {
  30. name: 'Operation',
  31. components: { InputGroup },
  32. data() {
  33. return {
  34. phone: '', // 手机号
  35. verifyCode: '', // 验证码
  36. btnTitle: '获取验证码',
  37. disabled: false, // 是否可点击
  38. errors: {} // 验证提示信息
  39. }
  40. },
  41. computed: {
  42. // 手机号和验证码都不能为空
  43. isClick() {
  44. if (!this.phone || !this.verifyCode) {
  45. return true
  46. } else {
  47. return false
  48. }
  49. }
  50. },
  51. created() { },
  52. methods: {
  53. getVerifyCode() {
  54. // 获取验证码
  55. if (this.validatePhone()) {
  56. this.validateBtn()
  57. // 发送网络请求
  58. this.$axios.post('/api/posts/sms_send', { tpl_id: '', key: '', phone: this.phone }).then(res => {
  59. console.log(res)
  60. })
  61. }
  62. },
  63. validatePhone() {
  64. // 判断输入的手机号是否合法
  65. if (!this.phone) {
  66. this.errors = {
  67. phone: '手机号码不能为空'
  68. }
  69. // return false
  70. } else if (!/^1[345678]\d{9}$/.test(this.phone)) {
  71. this.errors = {
  72. phone: '请输入正确是手机号'
  73. }
  74. // return false
  75. } else {
  76. this.errors = {}
  77. return true
  78. }
  79. },
  80. validateBtn() {
  81. // 倒计时
  82. let time = 60
  83. const timer = setInterval(() => {
  84. if (time == 0) {
  85. clearInterval(timer)
  86. this.disabled = false
  87. this.btnTitle = '获取验证码'
  88. } else {
  89. this.btnTitle = time + '秒后重试'
  90. this.disabled = true
  91. time--
  92. }
  93. }, 1000)
  94. },
  95. handleLogin() {
  96. // 点击发送
  97. this.errors = {}
  98. this.$axios.post('http://192.168.1.84:8081/authdata/api/posts/sms_back', {
  99. phone: this.phone,
  100. code: this.verifyCode
  101. }).then(res => {
  102. console.log(res)
  103. localStorage.setItem('ele_login', true)
  104. this.$router.push('/')
  105. }).catch(error => {
  106. // 返回错误信息
  107. this.errors = {
  108. code: error.response.data.msg
  109. }
  110. })
  111. }
  112. }
  113. }
  114. </script>