MySources.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { useEditor } from "@/modules/editor";
  2. import { initResource, useResource } from "@/modules/resource";
  3. import { css } from "@linaria/core";
  4. import { Image, List, Loadmore } from "@queenjs/ui";
  5. import { Radio } from "ant-design-vue";
  6. import { defineComponent, reactive } from "vue";
  7. export const MySources = defineComponent({
  8. setup() {
  9. const editor = useEditor();
  10. const resource = useResource();
  11. const state = reactive({
  12. sourceType: "Image" as "Image" | "Video",
  13. });
  14. function getCurrCtrl() {
  15. return resource.controls[
  16. state.sourceType === "Image"
  17. ? "materialImageListCtrl"
  18. : "materialVideoListCtrl"
  19. ];
  20. }
  21. function switchSource(v: "Image" | "Video") {
  22. state.sourceType = v;
  23. const ctrl = getCurrCtrl();
  24. ctrl.hasLimit = true;
  25. ctrl.loadPage(1);
  26. }
  27. function clickToDesign(url: string) {
  28. editor.actions.clickCompToDesign(state.sourceType, (comp) => {
  29. comp.value.url = url;
  30. });
  31. }
  32. switchSource("Image");
  33. return () => {
  34. const control =
  35. resource.controls[
  36. state.sourceType === "Image"
  37. ? "materialImageListCtrl"
  38. : "materialVideoListCtrl"
  39. ];
  40. return (
  41. <div class="space-y-20px -mt-10px flex flex-col overflow-hidden">
  42. <Radio.Group
  43. class={radioCls}
  44. value={state.sourceType}
  45. size="small"
  46. onChange={(e) => switchSource(e.target.value)}
  47. >
  48. <Radio.Button value="Image">图片</Radio.Button>
  49. <Radio.Button value="Video">视频</Radio.Button>
  50. </Radio.Group>
  51. <div class="scrollbar flex-1 -mr-15px pr-15px">
  52. <List data={control.state.list} columns={2} gap="20px">
  53. {{
  54. item(item: any) {
  55. return (
  56. <div
  57. style={{ aspectRatio: 1 }}
  58. onClick={() => clickToDesign(item.file.url)}
  59. >
  60. <Image
  61. class="w-full h-full"
  62. src={item.file.url}
  63. size={240}
  64. />
  65. </div>
  66. );
  67. },
  68. loadmore() {
  69. return (
  70. <Loadmore
  71. class="mt-20px"
  72. loading={control.state.loading}
  73. canLoad={control.state.canLoadNext}
  74. onChange={control.loadNextPage}
  75. />
  76. );
  77. },
  78. }}
  79. </List>
  80. </div>
  81. </div>
  82. );
  83. };
  84. },
  85. });
  86. const radioCls = css`
  87. display: flex;
  88. > label {
  89. flex: 1;
  90. width: 0;
  91. text-align: center;
  92. }
  93. `;