List.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import { useCtx } from "@/comm/ctx";
  2. import { useList } from "@/modules/list";
  3. import { css } from "@linaria/core";
  4. import { Image } from "@queenjs/ui";
  5. import { Button, Select, Space, Table } from "ant-design-vue";
  6. import { defineComponent, reactive } from "vue";
  7. import CategoryModal from "./categoryModal";
  8. export default defineComponent({
  9. setup() {
  10. const ctx = useList();
  11. const { store, showModal, actions } = ctx;
  12. const { deviceCtrl } = useCtx();
  13. const state = reactive({
  14. select: "default",
  15. optsions: [
  16. {
  17. label: "默认",
  18. value: "default",
  19. },
  20. ],
  21. });
  22. const columns = [
  23. {
  24. title: "封面图",
  25. dataIndex: "thumbnail",
  26. key: "thumbnail",
  27. customRender: ({ text }: any) => {
  28. return (
  29. <Image
  30. class="thumbnail"
  31. src={deviceCtrl.httpServer + text}
  32. size={0}
  33. />
  34. );
  35. },
  36. },
  37. {
  38. title: "名称",
  39. dataIndex: "name",
  40. key: "name",
  41. },
  42. ];
  43. actions.getAssetList();
  44. const initShowCategory = async () => {
  45. const appDataDir = deviceCtrl.appDataDir;
  46. const category = await deviceCtrl.ReadFileText(
  47. `${appDataDir}/screen/category.json`
  48. );
  49. const currentCategory = localStorage.getItem("category") || "default";
  50. state.select = currentCategory;
  51. if (!category.error && category.text) {
  52. const assets = JSON.parse(category.text);
  53. state.optsions = assets;
  54. }
  55. };
  56. const { msgCtrl } = useCtx();
  57. msgCtrl.screenModule = ctx;
  58. initShowCategory();
  59. msgCtrl.initScreen();
  60. const setShowCategory = (value: any) => {
  61. localStorage.setItem("category", value || "default");
  62. state.select = value;
  63. actions.getAssetList();
  64. };
  65. const createShowCategory = async () => {
  66. const { deviceCtrl } = useCtx();
  67. const res: any = await showModal(<CategoryModal />, {
  68. title: "新建分类",
  69. });
  70. const options = [...state.optsions];
  71. const optionItem = options.find((e) => {
  72. return e.value == res.value;
  73. });
  74. if (optionItem) {
  75. return;
  76. }
  77. options.push(res);
  78. state.optsions = options;
  79. const appDataDir = deviceCtrl.appDataDir;
  80. await deviceCtrl.WriteFileText(
  81. `${appDataDir}/screen/category.json`,
  82. JSON.stringify(options)
  83. );
  84. };
  85. return () => (
  86. <div class={ViewStyle}>
  87. <div class="table_header">
  88. <div class="title">展示列表</div>
  89. <div>
  90. <Space>
  91. <Select
  92. class={"select"}
  93. value={state.select}
  94. options={state.optsions}
  95. onChange={setShowCategory}
  96. ></Select>
  97. <Button
  98. type="primary"
  99. ghost
  100. onClick={() => {
  101. createShowCategory();
  102. }}
  103. >
  104. 新建展示分类
  105. </Button>
  106. </Space>
  107. </div>
  108. </div>
  109. <Table
  110. size="small"
  111. columns={columns}
  112. dataSource={store.list}
  113. rowKey={(record) => record?._id}
  114. ></Table>
  115. </div>
  116. );
  117. },
  118. });
  119. const ViewStyle = css`
  120. padding: 20px;
  121. .table_header {
  122. display: flex;
  123. align-items: center;
  124. justify-content: space-between;
  125. margin-bottom: 20px;
  126. .title {
  127. font-size: 18px;
  128. font-weight: bold;
  129. }
  130. .select {
  131. width: 150px;
  132. }
  133. }
  134. .ant-table-thead > tr > th,
  135. .ant-table-tbody > tr > td {
  136. text-align: center;
  137. }
  138. .thumbnail {
  139. width: 120px;
  140. object-fit: contain;
  141. }
  142. `;