index.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /* eslint-disable @next/next/no-img-element */
  2. "use client";
  3. import { useRouter } from "@/i18n/routing";
  4. import { useSignStore } from "@/stores/useSignStore";
  5. import { Mask } from "antd-mobile";
  6. import { FC, forwardRef, memo, useImperativeHandle, useRef, useState } from "react";
  7. import styles from "./style.module.scss";
  8. export interface SignInModalProps {
  9. onClose: () => void;
  10. onOpen: () => void;
  11. }
  12. interface BoxParams {
  13. startDays?: number;
  14. type?: "page" | "modal";
  15. }
  16. interface BoxList {
  17. handleOpening: (index: number) => void;
  18. }
  19. export const BoxListCom = forwardRef<BoxList, BoxParams>(function BoxListCom(
  20. { startDays = 1, type = "modal" }: BoxParams,
  21. ref
  22. ) {
  23. const signData = useSignStore((state) => state.signData);
  24. const handleOpening = (index: number) => {
  25. const box: any = document.getElementById(`box${index}`);
  26. box.src = "/sign/box/box-open.png";
  27. const img = document.getElementById(`opened${index}`);
  28. img ? (img.style.visibility = "visible") : null;
  29. };
  30. useImperativeHandle(ref, (): BoxList => {
  31. return {
  32. handleOpening,
  33. };
  34. });
  35. return (
  36. <>
  37. <div className={`w-[100%] ${type === "page" ? styles.page : styles.modal}`}>
  38. <div className="flex h-[100%] w-[100%] flex-wrap justify-start">
  39. {signData?.list?.map((item, index) => {
  40. return (
  41. <div className="h-[100%] w-[20%]" key={index}>
  42. <div className="h-[100%] w-[100%]">
  43. <div
  44. className={`relative text-center ${styles.text} text-[white]`}
  45. >
  46. <p>Day{item.id}</p>
  47. </div>
  48. <div className={`relative ${styles.box} w-[100%]`}>
  49. {/*onClick={(e) => handleOpening(startDays + index)}*/}
  50. <img
  51. id={"box" + (startDays + index)}
  52. src={
  53. item.is_suss
  54. ? "/sign/box/box-open.png"
  55. : item.extra_num
  56. ? "/sign/box_pay/gift.png"
  57. : "/sign/box/box.png"
  58. }
  59. className={"z-50 mx-[auto] h-[100%]"}
  60. alt=""
  61. />
  62. <div className="flex justify-center">
  63. {item.is_suss ? (
  64. <img
  65. id={"opened" + (startDays + index)}
  66. src={"/sign/opened.png"}
  67. className={
  68. "absolute bottom-[0.035rem] z-50 h-[0.34rem]"
  69. }
  70. alt=""
  71. />
  72. ) : null}
  73. </div>
  74. {item.extra_num ? (
  75. <div className="absolute bottom-0 left-0 right-0 mx-auto h-[30%] w-[90%] rounded border-[0.02rem] border-[green] bg-[black]">
  76. <p
  77. className={`${styles.green} text-center font-bold text-[green]`}
  78. >
  79. Extra +{item.extra_num}
  80. </p>
  81. </div>
  82. ) : null}
  83. </div>
  84. {item.extra_num ? (
  85. <div
  86. className={`${styles.lock} relative mt-[0.05rem] flex justify-center text-center font-bold text-[yellow]`}
  87. >
  88. <img
  89. id={"opened" + item.id}
  90. src="/sign/lock.png"
  91. className={"block h-[100%]"}
  92. alt=""
  93. />
  94. <span className="block">+{item.num}</span>
  95. </div>
  96. ) : null}
  97. </div>
  98. </div>
  99. );
  100. })}
  101. </div>
  102. </div>
  103. </>
  104. );
  105. });
  106. interface PayProps {
  107. type?: "page" | "modal";
  108. }
  109. export const PayBoxList: FC<PayProps> = ({ type = "modal" }) => {
  110. return (
  111. <>
  112. <div className="flex justify-center">
  113. {Array.from({ length: 4 }).map((item, index) => {
  114. return (
  115. <>
  116. <div
  117. className={`relative h-[100%] ${type === "page" ? styles.payPage : styles.payModal}`}
  118. >
  119. <div className="relative flex h-[0.89rem] justify-center font-bold">
  120. <span className="absolute top-[0.005rem] z-50 leading-[] text-[white]">
  121. 5R
  122. </span>
  123. <img
  124. src="/sign/box_pay/bg.png"
  125. className={"z-10 h-[100%]"}
  126. alt=""
  127. />
  128. <img
  129. src="/sign/box_pay/bg2.png"
  130. className={"absolute bottom-0 z-30 h-[0.355rem]"}
  131. alt=""
  132. />
  133. <img
  134. src="/sign/box_pay/gift.png"
  135. className={"absolute top-[0.18rem] z-20 h-[0.505rem]"}
  136. alt=""
  137. />
  138. <img
  139. id={"lock" + index}
  140. src="/sign/box_pay/lock.png"
  141. className={"absolute bottom-[0.17rem] z-40 h-[0.315rem]"}
  142. alt=""
  143. />
  144. <img
  145. id={"opened" + index}
  146. src="/sign/opened.png"
  147. className={"absolute bottom-[0.3rem] z-40 h-[0.34rem]"}
  148. alt=""
  149. />
  150. <span className="absolute bottom-[0.005rem] z-50 text-[white]">
  151. 50R
  152. </span>
  153. </div>
  154. <div
  155. className={`${styles.text} text-center font-bold text-[white]`}
  156. >
  157. <span>
  158. Day{index === 3 ? 10 + index * 5 + 5 : 10 + index * 5}
  159. </span>
  160. </div>
  161. </div>
  162. </>
  163. );
  164. })}
  165. </div>
  166. </>
  167. );
  168. };
  169. const SignInModal = forwardRef(function SignInModal(props, ref) {
  170. const [visible, setVisible] = useState(false);
  171. const signData = useSignStore((state) => state.signData);
  172. const activity_id = useSignStore((state) => state.activity_id);
  173. const totalData = signData.list;
  174. const isSignNum = totalData?.reduce((pre, cur) => (cur.is_suss ? pre + 1 : pre), 0);
  175. const router = useRouter();
  176. const boxRef = useRef(null);
  177. useImperativeHandle(ref, () => {
  178. return {
  179. onClose: () => setVisible(false),
  180. onOpen: () => setVisible(true),
  181. };
  182. });
  183. return (
  184. <>
  185. <Mask visible={visible} destroyOnClose={true} onMaskClick={() => setVisible(false)}>
  186. <div
  187. className={"absolute right-[0.2083rem] top-[18%] z-50"}
  188. onClick={() => setVisible(false)}
  189. >
  190. <span className={"iconfont icon-guanbi"}></span>
  191. </div>
  192. <div className="absolute top-[5%] w-[100%]">
  193. <div className={"relative h-[6.25rem] w-[100%]"}>
  194. <div className={"h-[100%]"}>
  195. <div className="absolute flex h-[100%] w-[100%] justify-center overflow-hidden">
  196. <img
  197. src="/sign/light2.png"
  198. className={"absolute top-[-1.215rem] h-[7.5rem] max-w-[none]"}
  199. alt=""
  200. />
  201. <img
  202. src="/sign/light.png"
  203. className={"absolute h-[5.07rem] max-w-[none]"}
  204. alt=""
  205. />
  206. </div>
  207. {/* 主题背景图 */}
  208. <div className="relative flex h-[3rem] w-[100%] justify-center">
  209. <img src="/sign/theme.png" className={"absolute h-[100%]"} alt="" />
  210. </div>
  211. <div className="absolute top-[30%] h-[3.95rem] w-[100%]">
  212. <div className="flex h-[100%] justify-center">
  213. {/* 宽度自动填充适应活动背景图宽度 */}
  214. <div className="relative h-[100%]">
  215. <img
  216. src={
  217. signData.background_type === 1
  218. ? "/sign/bg2.png"
  219. : signData.Background
  220. }
  221. className={"h-[100%]"}
  222. alt=""
  223. />
  224. {/* 右上角倒计时 */}
  225. <div className="absolute right-[0.15rem] top-0 z-50 flex h-[0.3rem] w-[20%] items-center justify-center space-x-[2px] text-center text-[0.125rem] font-bold text-[white]">
  226. {/*<p
  227. className={"h-[0.15rem]"}>{totalData?.length}</p>*/}
  228. {/*<p className={"h-[0.15rem] text-[yellow]"}>Day 20</p>*/}
  229. <p className={"text-[yellow]"}>{isSignNum}</p>
  230. <span>/</span>
  231. <p>{totalData?.length}</p>
  232. </div>
  233. {/* 签到body */}
  234. <div className="absolute left-0 top-0 w-[100%]">
  235. <div className="relative mt-[0.51rem] w-[100%]">
  236. <BoxListCom ref={boxRef} />
  237. <div
  238. className="mt-[0.25rem] flex h-[0.62rem] justify-center"
  239. onClick={() => {
  240. router.push(
  241. `/signin?activity_id=${activity_id}`
  242. );
  243. }}
  244. >
  245. <img
  246. src={
  247. signData?.is_op
  248. ? "/sign/button.png"
  249. : "/sign/button_signed.png"
  250. }
  251. className={"h-[100%]"}
  252. alt=""
  253. />
  254. <span className="absolute text-[0.16rem] font-bold leading-[0.375rem]">
  255. Sign-in
  256. </span>
  257. </div>
  258. </div>
  259. </div>
  260. </div>
  261. </div>
  262. </div>
  263. </div>
  264. </div>
  265. </div>
  266. </Mask>
  267. </>
  268. );
  269. });
  270. export default memo(SignInModal);