home.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. const { createApp, ref ,onMounted,createVNode, render} = Vue
  2. createApp({
  3. setup() {
  4. onMounted(()=>{
  5. countX()
  6. listData()
  7. _newsListData()
  8. if (isMobile()) {
  9. setTimeout(initBrandSwipe, 500)
  10. }
  11. })
  12. const form = ref({
  13. name:'',
  14. phonenumber:'',
  15. notes:''
  16. })
  17. // 添加错误信息和提交状态
  18. const errors = ref({
  19. name: '',
  20. phonenumber: ''
  21. })
  22. const isSubmitting = ref(false)
  23. const lastSubmitTime = ref(0)
  24. // 验证函数
  25. const validateForm = () => {
  26. errors.value = { name: '', phonenumber: '' }
  27. let isValid = true
  28. // 验证姓名
  29. if (!form.value.name.trim()) {
  30. errors.value.name = '请输入姓名'
  31. isValid = false
  32. } else if (form.value.name.trim().length < 2) {
  33. errors.value.name = '姓名不可少于2位'
  34. isValid = false
  35. } else if (/^\d+$/.test(form.value.name.trim())) {
  36. errors.value.name = '姓名不能是数字'
  37. isValid = false
  38. }
  39. // 验证电话
  40. if (!form.value.phonenumber.trim()) {
  41. errors.value.phonenumber = '请输入联系方式'
  42. isValid = false
  43. } else if (form.value.phonenumber.trim().length < 5) {
  44. errors.value.phonenumber = '联系方式不可少于5位'
  45. isValid = false
  46. }
  47. return isValid
  48. }
  49. // 重置表单
  50. const resetForm = () => {
  51. form.value = {
  52. name: '',
  53. phonenumber: '',
  54. notes: ''
  55. }
  56. errors.value = {
  57. name: '',
  58. phonenumber: ''
  59. }
  60. }
  61. const submit = async (id)=>{
  62. console.log(form.value)
  63. // 检查是否在10秒内重复提交
  64. const currentTime = Date.now()
  65. if (currentTime - lastSubmitTime.value < 20000) {
  66. tool.alert('20秒内不可重复提交')
  67. return
  68. }
  69. // 验证表单
  70. if (!validateForm()) {
  71. return
  72. }
  73. // 检查留言是否为空
  74. if (form.value.notes.trim() === '') {
  75. tool.alert('请填写留言内容')
  76. return
  77. }
  78. // 设置提交状态
  79. isSubmitting.value = true
  80. lastSubmitTime.value = currentTime
  81. try {
  82. const res = await instance.post('',{
  83. "id": 2024082809051903,
  84. "content":{
  85. "sat_orderclueid": 0,
  86. "siteid": "HY",
  87. "name": form.value.name.trim(),
  88. "phonenumber": form.value.phonenumber.trim(),
  89. "notes": form.value.notes.trim()
  90. }
  91. })
  92. if (res.data.code == 1) {
  93. tool.alert('提交成功')
  94. resetForm()
  95. } else {
  96. alert(res.data.msg)
  97. }
  98. } catch (error) {
  99. console.error('提交失败:', error)
  100. tool.alert('提交失败,请稍后重试')
  101. } finally {
  102. isSubmitting.value = false
  103. }
  104. }
  105. const x_count = ref(0)
  106. const countX = async (id)=>{
  107. const res = await instance.post('',{
  108. "id": "2024101210472203",
  109. "content": {
  110. "siteid":"hy"
  111. }
  112. })
  113. x_count.value = res.data.data
  114. }
  115. setupFlip = (tick)=> {
  116. Tick.helper.interval(function() {
  117. tick.value ++;
  118. if (tick.value == 5181234 + x_count.value * 123)
  119. return false
  120. tick.root.setAttribute('aria-label', tick.value);
  121. }, 1000);
  122. }
  123. const timeLine = ref(0)
  124. const timer = ref(null)
  125. const stopClick = ref(false)
  126. function syncBrandView(idx) {
  127. $('.mobdot').removeClass('mobactive');
  128. $('.mobdot' + (idx + 1)).addClass('mobactive')
  129. $('.box3RigImgItem').removeClass('active').eq(idx).addClass('active')
  130. $('.brand-timeline-swiper .swiper-wrapper').css({
  131. 'transform': 'translateX(-' + (idx * 100) + '%)',
  132. 'transition': 'transform 0.3s ease'
  133. })
  134. }
  135. cardPrev = () => {
  136. stopClick.value = true
  137. if (timer.value) {
  138. clearTimeout(timer.value)
  139. }
  140. timer.value = setTimeout(()=>{
  141. timeLine.value --
  142. syncBrandView(timeLine.value)
  143. stopClick.value = false
  144. },500)
  145. }
  146. cardNext = ()=> {
  147. stopClick.value = true
  148. if (timer.value) {
  149. clearTimeout(timer.value)
  150. }
  151. timer.value = setTimeout(()=>{
  152. timeLine.value ++
  153. syncBrandView(timeLine.value)
  154. stopClick.value = false
  155. },500)
  156. }
  157. function initBrandSwipe() {
  158. var container = document.querySelector('.mbox3Rig')
  159. if (!container) return
  160. var startX = 0, startY = 0, isSwiping = false
  161. container.addEventListener('touchstart', function(e) {
  162. startX = e.touches[0].clientX
  163. startY = e.touches[0].clientY
  164. isSwiping = false
  165. }, {passive: true})
  166. container.addEventListener('touchmove', function(e) {
  167. if (!startX) return
  168. var dx = Math.abs(e.touches[0].clientX - startX)
  169. var dy = Math.abs(e.touches[0].clientY - startY)
  170. if (dx > 10 && dx > dy) {
  171. isSwiping = true
  172. }
  173. }, {passive: true})
  174. container.addEventListener('touchend', function(e) {
  175. if (!startX || !isSwiping) { startX = 0; return }
  176. var diffX = startX - e.changedTouches[0].clientX
  177. if (Math.abs(diffX) > 50) {
  178. if (diffX > 0 && timeLine.value < 10) {
  179. timeLine.value++
  180. syncBrandView(timeLine.value)
  181. } else if (diffX < 0 && timeLine.value > 0) {
  182. timeLine.value--
  183. syncBrandView(timeLine.value)
  184. }
  185. }
  186. startX = 0
  187. isSwiping = false
  188. }, {passive: true})
  189. }
  190. const pjdata = ref([])
  191. const listData = async ()=>{
  192. const res = await instance.post('',{
  193. id:20240801133603,
  194. content:{
  195. siteid:"HY",
  196. pageNumber:1,
  197. pageSize:9,
  198. where:{
  199. "status":'发布',
  200. "condition":"",
  201. }
  202. }
  203. })
  204. pjdata.value = res.data.data
  205. }
  206. const newsData = ref([])
  207. const _newsListData = async (id)=>{
  208. const res = await instance.post('',{
  209. id:20240727135603,
  210. content:{
  211. siteid:"HY",
  212. pageNumber:1,
  213. pageSize:3,
  214. where:{
  215. "condition":"",
  216. "status":'发布'
  217. }
  218. }
  219. })
  220. newsData.value = res.data.data
  221. console.log(res,'---')
  222. }
  223. const isMobile = ()=> {
  224. // 判断是否为移动设备
  225. return (
  226. typeof window.orientation !== "undefined" || // 判断是否存在window.orientation属性,此属性在移动设备上一般存在
  227. navigator.userAgent.indexOf('IEMobile') !== -1 || // 判断是否为Windows Phone
  228. navigator.userAgent.indexOf('iPhone') !== -1 || // 判断是否为iPhone
  229. navigator.userAgent.indexOf('Android') !== -1 && navigator.userAgent.indexOf('Mobile') !== -1 || // 判断是否为Android手机
  230. navigator.userAgent.indexOf('BlackBerry') !== -1 || // 判断是否为BlackBerry
  231. navigator.userAgent.indexOf('Opera Mini') !== -1 // 判断是否为Opera Mini浏览器
  232. );
  233. }
  234. return {
  235. listData,
  236. newsData,
  237. pjdata,
  238. stopClick,
  239. timeLine,
  240. cardPrev,
  241. cardNext,
  242. submit,
  243. x_count,
  244. setupFlip,
  245. form,
  246. errors,
  247. isSubmitting,
  248. resetForm,
  249. isMobile
  250. }
  251. }
  252. }).mount('#hmpage')