index.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { Dict_Imgs } from "@/dict";
  2. import { css } from "@linaria/core";
  3. import { defineComponent, reactive, watch } from "vue";
  4. import { any } from "vue-types";
  5. import { Image, Text } from "../..";
  6. import { options } from "./options";
  7. export const CardDemo = defineComponent({
  8. props: {
  9. value: any<typeof options.value>().isRequired,
  10. },
  11. setup(props) {
  12. const state = reactive(props.value);
  13. watch(
  14. () => [state.cardColumns],
  15. () => {
  16. const { cardColumns, list } = state;
  17. const offset = cardColumns - list.length;
  18. if (offset > 0) {
  19. Array.from({ length: offset }, () => {
  20. list.push({ name: "name", img: Dict_Imgs.Default, desc: "xxx" });
  21. });
  22. } else {
  23. list.splice(cardColumns, offset * -1);
  24. }
  25. }
  26. );
  27. return () => (
  28. <>
  29. <Text v-model={[state.title, "value"]} />
  30. <Text v-model={[state.desc, "value"]} />
  31. <div class="flex space-x-16px">
  32. {state.list.map((d, i) => (
  33. <div class="w-0 flex-1 relative">
  34. <Image
  35. class={imgStyle}
  36. style={{ borderColor: state.themeColor }}
  37. v-model={[d.img, "value"]}
  38. />
  39. <div
  40. class={numberStyle}
  41. style={{ backgroundColor: state.themeColor }}
  42. >
  43. {(++i / 100).toString().split(".")[1]}
  44. </div>
  45. <Text class="mt-24px" v-model={[d.name, "value"]} />
  46. <Text v-model={[d.desc, "value"]} />
  47. </div>
  48. ))}
  49. </div>
  50. </>
  51. );
  52. },
  53. });
  54. const imgStyle = css`
  55. border-bottom: 2px solid;
  56. `;
  57. const numberStyle = css`
  58. position: absolute;
  59. left: 50%;
  60. border-radius: 50%;
  61. width: 40px;
  62. height: 40px;
  63. text-align: center;
  64. line-height: 40px;
  65. box-sizing: content-box;
  66. border: 3px solid #fff;
  67. transform: translate(-50%, -50%);
  68. `;