index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <view class="container">
  3. <img class="img" src="@/static/images/school-logo.jpg" />
  4. <view class="logo_name">万载三中</view>
  5. <!-- 手机号码输入框区域 -->
  6. <view class="phone">
  7. <input class="phone_input" type="text" placeholder="手机号" placeholder-style="color:#CCCCCC;" v-model="phone" />
  8. </view>
  9. <!-- 验证码区域 -->
  10. <view class="code">
  11. <input class="code_input" type="text" placeholder="验证码" placeholder-style="color:#CCCCCC;" v-model="codeValue" />
  12. <uv-code uniqueKey="login" keepRunning ref="codeDom" @change="codeChange"></uv-code>
  13. <view class="code_box" @click="getCode">{{ tips }}</view>
  14. </view>
  15. <!-- 登录按钮区域 -->
  16. <view class="loginBtn" :class="{ active: btnFlag }" @click="handleLogin">登录</view>
  17. </view>
  18. </template>
  19. <script setup>
  20. import { ref, computed } from 'vue'
  21. import { onLoad } from '@dcloudio/uni-app'
  22. import { myRequest } from '@/utils/api.js'
  23. // 手机号码
  24. const phone = ref('')
  25. // 验证码
  26. const codeValue = ref('')
  27. // 验证码Dom
  28. const codeDom = ref(null)
  29. // 登录按钮是否高亮
  30. const btnFlag = computed(() => {
  31. // 手机号码验证规则
  32. const regPhone = /^1[3-9]\d{9}$/
  33. if (phone.value && regPhone.test(phone.value) && codeValue.value) {
  34. return true
  35. } else {
  36. return false
  37. }
  38. })
  39. // 提示语
  40. const tips = ref('')
  41. // 家长
  42. const plist = ref(['学生轨迹', '消息通知', '访客预约', '校园预警'])
  43. // 老师
  44. const tlist = ref(['学生轨迹', '消息通知', '访客预约', '校园预警', '通讯录'])
  45. onLoad(() => {})
  46. // 获取验证码按钮点击回调
  47. const getCode = () => {
  48. // 手机号码验证规则
  49. const regPhone = /^1[3-9]\d{9}$/
  50. if (phone.value && regPhone.test(phone.value)) {
  51. if (codeDom.value.canGetCode) {
  52. // 模拟向后端请求验证码
  53. uni.showLoading({
  54. title: '正在获取验证码'
  55. })
  56. setTimeout(() => {
  57. uni.hideLoading()
  58. uni.showToast({
  59. title: '验证码已发送',
  60. icon: 'none'
  61. })
  62. codeDom.value.start()
  63. }, 2000)
  64. } else {
  65. uni.showToast({
  66. title: '倒计时结束后再发送',
  67. icon: 'none'
  68. })
  69. }
  70. } else {
  71. uni.showToast({
  72. title: '请先输入正确的手机号码',
  73. icon: 'none'
  74. })
  75. }
  76. }
  77. // 登录按钮回调
  78. const handleLogin = () => {
  79. // const flag = verifyValue()
  80. // if (flag) {
  81. // uni.setStorageSync('userId', 25)
  82. // uni.setStorageSync('userType', 1)
  83. // uni.navigateTo({
  84. // url: '/pages/home/home'
  85. // })
  86. // }
  87. // 0 代表家长 1 代表老师
  88. let userType = 1
  89. uni.setStorageSync('userType', userType)
  90. if (userType == 0) {
  91. uni.setStorageSync('appList', plist.value)
  92. uni.setStorageSync('userId', 25)
  93. } else {
  94. uni.setStorageSync('appList', tlist.value)
  95. uni.setStorageSync('userId', 26)
  96. }
  97. uni.navigateTo({
  98. url: '/pages/home/home'
  99. })
  100. }
  101. // 验证表格数据是否符合规范
  102. const verifyValue = () => {
  103. // 手机号码验证规则
  104. const regPhone = /^1[3-9]\d{9}$/
  105. if (!phone.value) {
  106. uni.showToast({
  107. title: '请输入手机号',
  108. icon: 'none'
  109. })
  110. return false
  111. }
  112. if (!regPhone.test(phone.value)) {
  113. uni.showToast({
  114. title: '手机号码格式错误',
  115. icon: 'none'
  116. })
  117. return false
  118. }
  119. if (!codeValue.value) {
  120. uni.showToast({
  121. title: '请输入验证码',
  122. icon: 'none'
  123. })
  124. return false
  125. }
  126. return true
  127. }
  128. const codeChange = (text) => {
  129. tips.value = text
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. .container {
  134. display: flex;
  135. flex-direction: column;
  136. align-items: center;
  137. min-height: 100vh;
  138. background-color: #f8f8fa;
  139. .img {
  140. margin-top: 120rpx;
  141. width: 200rpx;
  142. height: 200rpx;
  143. border-radius: 20rpx;
  144. }
  145. .logo_name {
  146. margin-top: 25rpx;
  147. font-size: 36rpx;
  148. }
  149. .phone {
  150. box-sizing: border-box;
  151. margin-top: 80rpx;
  152. padding: 0 20rpx;
  153. width: 538rpx;
  154. height: 80rpx;
  155. border-radius: 8rpx;
  156. box-shadow: 0 0 10rpx #ccc;
  157. background-color: #fff;
  158. .phone_input {
  159. height: 100%;
  160. }
  161. }
  162. .code {
  163. display: flex;
  164. justify-content: space-between;
  165. align-items: center;
  166. box-sizing: border-box;
  167. margin-top: 40rpx;
  168. padding: 0 20rpx;
  169. width: 538rpx;
  170. height: 80rpx;
  171. border-radius: 8rpx;
  172. box-shadow: 0 0 10rpx #ccc;
  173. background-color: #fff;
  174. .code_input {
  175. width: 55%;
  176. height: 100%;
  177. }
  178. .code_box {
  179. display: flex;
  180. justify-content: center;
  181. align-items: center;
  182. width: 35%;
  183. height: 80rpx;
  184. color: #3c9cff;
  185. font-size: 26rpx;
  186. }
  187. }
  188. .loginBtn {
  189. display: flex;
  190. justify-content: center;
  191. align-items: center;
  192. margin-top: 50rpx;
  193. width: 538rpx;
  194. height: 80rpx;
  195. color: #a0a1a4;
  196. border-radius: 8rpx;
  197. background-color: #e5e6eb;
  198. }
  199. .active {
  200. color: #fff;
  201. background-color: #0061ff;
  202. }
  203. }
  204. </style>