index.tsx 5.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { View, Image } from "@tarojs/components";
  2. import Taro, { useRouter } from "@tarojs/taro";
  3. import { getPage } from "@src/server/index/index";
  4. import { useEffect, useState } from "react";
  5. function LdPage() {
  6. let systemInfo = Taro.getSystemInfoSync();
  7. let [data, setDate] = useState<any>(null)
  8. const router = useRouter()
  9. useEffect(() => {
  10. let params = router.params
  11. console.log("router", router.params)
  12. if (params.pageId) {
  13. Taro.showLoading({
  14. title: '加载中',
  15. })
  16. getPage(params.pageId).then((res: any) => {
  17. if (res.data.code === 200) {
  18. let content = res.data.data.content
  19. try {
  20. content = JSON.parse(content)
  21. } catch (error) {
  22. console.log("error", error)
  23. }
  24. let obj = {
  25. }
  26. console.log("content", content)
  27. content?.elementsSpecList?.map((item, index) => {
  28. if (item.elementType === "QR_CODE") {
  29. let url = res.data.data.qrCodeList.find(q => q.siteId == item.id)?.urlList[0]
  30. obj[item.elementType] = { ...item, url, eq: index }
  31. } else if (item.elementType === "FLOAT_BUTTON") {
  32. let url = res.data.data.qrCodeFloatList.find(q => q.siteId == item.id)?.urlList[0]
  33. console.log("url", url)
  34. obj[item.elementType] = { ...item, url, eq: index }
  35. } else if (item.elementType === "TEXT") {
  36. obj[item.elementType] = obj[item.elementType] ? [...obj[item.elementType], { ...item, eq: index }] : [{ ...item, eq: index }]
  37. } else if (item.elementType === "IMAGE") {
  38. obj[item.elementType] = obj[item.elementType] ? [...obj[item.elementType], { ...item, eq: index }] : [{ ...item, eq: index }]
  39. } else {
  40. obj[item.elementType] = { ...item, eq: index }
  41. }
  42. })
  43. setDate({ ...res.data.data, ...obj })
  44. }
  45. Taro.hideLoading()
  46. })
  47. }
  48. }, [])
  49. const onLongPress = (str) => {
  50. console.log("用户长按了二维码:",str)
  51. }
  52. return <View >
  53. <View style={{ marginTop: (systemInfo.statusBarHeight as any) + 10 }}></View>
  54. {/* 标题 */}
  55. <View style={{ textAlign: 'center', paddingBottom: 10 }}>{data ? data["name"] : ""}&nbsp;</View>
  56. {/* 内容 */}
  57. <View style={{ height: `calc(100vh - ${(systemInfo.statusBarHeight || 0) + 32}px)`, backgroundColor: "#d5e8d6", overflowY: "auto" }}>
  58. {
  59. data ? <View style={{ display: 'flex', flexFlow: 'column', paddingBottom: 100 }}>
  60. {/* 顶图 */}
  61. {data["TOP_IMAGE"] && <Image src={data["TOP_IMAGE"].url} mode="widthFix" style={{ height: "auto", width: "100vw", order: data["TOP_IMAGE"].eq }} />}
  62. {/* 文本 */}
  63. {data["TEXT"] && data["TEXT"].map((textObj, index) => {
  64. return index === 0 ? <View style={{ fontSize: 24, fontWeight: "bold", color: "", padding: "10px 20px", display: 'grid', gap: 10, order: textObj.eq }}>{textObj?.text?.split(/\s/ig)?.map((item, index) => {
  65. return <View style={index === 0 ? { color: "#D0021B", marginBottom: -10 } : {}}>{item}</View>
  66. })}</View> : <View style={{ fontSize: 24, fontWeight: "bold", color: "", padding: "10px 20px", display: 'grid', gap: 10, order: textObj.eq }}>{textObj?.text?.split(/\s/ig)?.map((item, index) => {
  67. return <View>{item}</View>
  68. })}</View>
  69. })}
  70. {/* 图 */}
  71. {data["IMAGE"] && data["IMAGE"].map((imgObj, index) => {
  72. return <Image src={imgObj.url} mode="widthFix" style={{ height: "auto", width: "100vw", order: imgObj.eq }} />
  73. })}
  74. {/* 二维码 */}
  75. {data["QR_CODE"] && <Image src={data["QR_CODE"].url} onLongPress={()=>{onLongPress("QR_CODE")}} mode="widthFix" showMenuByLongpress style={{ height: "auto", width: "70vw", display: 'block', margin: '0 auto', order: data["QR_CODE"].eq }} />}
  76. {/* 动图 */}
  77. {/* <Image src={"https://app-cloud-images.oss-cn-hangzhou.aliyuncs.com/1768559009681.gif"} mode="widthFix" style={{ height: "auto", width: "100vw", marginTop: -30, paddingBottom: 70 }} /> */}
  78. {/* 底部浮选图 */}
  79. {data["FLOAT_BUTTON"] && <Image src={data["FLOAT_BUTTON"].url} mode="widthFix" onLongPress={()=>{onLongPress("FLOAT_BUTTON")}}showMenuByLongpress style={{ height: "auto", width: "100vw", position: 'fixed', bottom: 0, left: 0, zIndex: 999, order: data["FLOAT_BUTTON"].eq }} />}
  80. </View> : <View></View>
  81. }
  82. </View>
  83. </View>
  84. }
  85. export default LdPage;