index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <RightFillPano>
  3. <template #header>
  4. <ui-group borderBottom>
  5. <template #header>
  6. <ui-button @click="editTagging = createTagging()">
  7. <ui-icon type="add" />
  8. {{$t('sys.add')}}
  9. </ui-button>
  10. </template>
  11. </ui-group>
  12. </template>
  13. <ui-group :title="$t('tagging.list')" class="tagging-list">
  14. <template #header>
  15. <StyleTypeSelect v-model:value="type" all count />
  16. </template>
  17. <template #icon>
  18. <ui-icon
  19. ctrl
  20. :class="{ active: showSearch }"
  21. type="search"
  22. @click="showSearch = !showSearch"
  23. style="margin-right: 20px"
  24. />
  25. <ui-icon
  26. ctrl
  27. :type="custom.showTaggings ? 'eye-s' : 'eye-n'"
  28. @click="custom.showTaggings = !custom.showTaggings"
  29. />
  30. </template>
  31. <ui-group-option v-if="showSearch">
  32. <ui-input type="text" width="100%" :placeholder="$t('sys.save')" v-model="keyword">
  33. <template #preIcon>
  34. <ui-icon type="search" />
  35. </template>
  36. </ui-input>
  37. </ui-group-option>
  38. <TagingSign
  39. v-for="tagging in filterTaggings"
  40. :key="tagging.id"
  41. :tagging="tagging"
  42. :selected="selectTagging === tagging"
  43. @edit="editTagging = tagging"
  44. @delete="deleteTagging(tagging)"
  45. @select="(selected) => (selectTagging = selected ? tagging : null)"
  46. @fixed="fixedTagging(tagging)"
  47. />
  48. </ui-group>
  49. </RightFillPano>
  50. <Edit
  51. v-if="editTagging"
  52. :data="editTagging"
  53. @quit="editTagging = null"
  54. @save="saveHandler"
  55. />
  56. </template>
  57. <script lang="ts" setup>
  58. import Edit from "./edit.vue";
  59. import TagingSign from "./sign.vue";
  60. import StyleTypeSelect from "./style-type-select.vue";
  61. import { RightFillPano } from "@/layout";
  62. import { useViewStack } from "@/hook";
  63. import { computed, ref, watchEffect } from "vue";
  64. import { router, RoutesName } from "@/router";
  65. import { custom } from "@/env";
  66. import {
  67. taggings,
  68. getTaggingStyle,
  69. Tagging,
  70. autoSaveTaggings,
  71. createTagging,
  72. getTaggingPositions,
  73. taggingPositions,
  74. isOld,
  75. save,
  76. getTagging,
  77. TaggingStyle,
  78. } from "@/store";
  79. import { taggingsGroup } from "@/sdk";
  80. const showSearch = ref(false);
  81. const type = ref<TaggingStyle["typeId"]>(-1);
  82. const keyword = ref("");
  83. const filterTaggings = computed(() =>
  84. taggings.value.filter((tagging) => {
  85. if (!tagging.title.includes(keyword.value)) return false;
  86. if (type.value === -1) return true;
  87. const style = getTaggingStyle(tagging.styleId);
  88. return style?.typeId === type.value;
  89. })
  90. );
  91. const editTagging = ref<Tagging | null>(null);
  92. const saveHandler = (tagging: Tagging) => {
  93. if (!editTagging.value) return;
  94. if (!getTagging(editTagging.value.id)) {
  95. taggings.value.push(tagging);
  96. const style = getTaggingStyle(tagging.styleId);
  97. if (style) {
  98. style.lastUse = 1;
  99. }
  100. } else {
  101. Object.assign(editTagging.value, tagging);
  102. }
  103. editTagging.value = null;
  104. };
  105. const deleteTagging = (tagging: Tagging) => {
  106. const index = taggings.value.indexOf(tagging);
  107. const positions = getTaggingPositions(tagging);
  108. taggingPositions.value = taggingPositions.value.filter(
  109. (position) => !positions.includes(position)
  110. );
  111. taggings.value.splice(index, 1);
  112. };
  113. const fixedTagging = async (tagging: Tagging) => {
  114. if (isOld.value) {
  115. await save();
  116. }
  117. router.push({ name: RoutesName.taggingPosition, params: { id: tagging.id } });
  118. };
  119. const selectTagging = ref<Tagging | null>(null);
  120. useViewStack(() => {
  121. const stopAuth = autoSaveTaggings();
  122. const stop = watchEffect((onCleanup) => {
  123. taggingsGroup.changeCanMove(true);
  124. taggingsGroup.showDelete(true);
  125. onCleanup(() => {
  126. taggingsGroup.changeCanMove(false);
  127. taggingsGroup.showDelete(false);
  128. });
  129. });
  130. return () => {
  131. stop();
  132. stopAuth();
  133. };
  134. });
  135. </script>
  136. <style scoped>
  137. .active {
  138. color: var(--color-main-normal) !important;
  139. }
  140. .tagging-list {
  141. padding-bottom: 30px;
  142. }
  143. </style>