LeftPanel.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { useResource } from "@/modules/resource";
  2. import { cx } from "@linaria/core";
  3. import { useQueditor } from "@queenjs-modules/queditor";
  4. import { switchSceneProdComp } from "@queenjs-modules/queditor/module/controls/Queen3dCtrl/actions/geom";
  5. import { Pack } from "@queenjs-modules/queditor/objects";
  6. import { AssetItemFile } from "@queenjs-modules/queentree-explorer/objects/fileSystem/assetFiles";
  7. import { Image, List } from "@queenjs/ui";
  8. import { Button } from "ant-design-vue";
  9. import { defineComponent } from "vue";
  10. import { any, bool } from "vue-types";
  11. import LibraryModal from "./LibraryModal";
  12. export default defineComponent({
  13. setup() {
  14. const resource = useResource();
  15. const queditor = useQueditor();
  16. const replaceMesh = async () => {
  17. const res = await resource.showModal<AssetItemFile>(<LibraryModal />, {
  18. width: "900px",
  19. });
  20. console.log("res: ", res);
  21. const pack = await res.getAssetDetail();
  22. const data = queditor.helper.getRelatedSourceByProduct(
  23. pack.source as Pack["source"],
  24. res.state.id
  25. );
  26. console.log("data: ", data);
  27. queditor.actions.insertMesh(data);
  28. };
  29. return () => {
  30. const list = resource.store.sourceDetail.webEditor?.meshSlots || [];
  31. return (
  32. <div class="w-300px flex flex-col">
  33. <div class="p-15px text-16px text-white border-dark-800 border-0 border-b-1 border-solid">
  34. 模型列表
  35. </div>
  36. <List data={list} gap="10px" class="scrollbar flex-1 py-15px px-15px">
  37. {{
  38. item: (record: any) => (
  39. <ProductItem
  40. record={record}
  41. onChange={replaceMesh}
  42. active={record.Id == resource.store.selectedId}
  43. onClick={() => {
  44. // queditor.
  45. debugger;
  46. switchSceneProdComp.call(
  47. queditor.controls.queen3dCtrl,
  48. queditor.store.pack.scenes[0].products[0].prodId,
  49. record.meshName
  50. );
  51. resource.store.setSelectedId(record.Id);
  52. }}
  53. />
  54. ),
  55. loadmore: () => (
  56. <div class="text-center py-20px text-12px opacity-80">
  57. 没有更多了
  58. </div>
  59. ),
  60. }}
  61. </List>
  62. </div>
  63. );
  64. };
  65. },
  66. });
  67. const ProductItem = defineComponent({
  68. props: {
  69. record: any().isRequired,
  70. active: bool().def(false),
  71. },
  72. emits: ["change", "click"],
  73. setup(props, { emit }) {
  74. return () => {
  75. const { active, record } = props;
  76. return (
  77. <div
  78. style={{ backgroundColor: "#303030" }}
  79. class={cx(
  80. "flex items-center py-6px px-12px rounded-4px border-1 border-solid cursor-pointer hover:opacity-80 transition-all",
  81. active ? "border-orange-200" : "border-transparent"
  82. )}
  83. onClick={() => emit("click", record)}
  84. >
  85. <Image src={record.thumbnail} class="w-48px rounded-4px" />
  86. <div class="ml-10px flex-1 mr-5px truncate w-0">
  87. {record.meshName || "未命名"}
  88. </div>
  89. <Button
  90. type="primary"
  91. ghost
  92. size="small"
  93. onClick={(e) => {
  94. e.stopPropagation();
  95. emit("change", record);
  96. }}
  97. >
  98. 替换
  99. </Button>
  100. </div>
  101. );
  102. };
  103. },
  104. });