|
| 1 | +<template> |
| 2 | + <q-list> |
| 3 | + <div p="x-4 y-2"> |
| 4 | + <q-input |
| 5 | + dense |
| 6 | + outlined |
| 7 | + v-model="filter" |
| 8 | + clearable |
| 9 | + placeholder="搜索 Artifacts..." |
| 10 | + /> |
| 11 | + </div> |
| 12 | + <q-item |
| 13 | + v-for="artifact in filteredArtifacts" |
| 14 | + :key="artifact.id" |
| 15 | + clickable |
| 16 | + @click="openArtifact(artifact)" |
| 17 | + :class="{ 'route-active': artifact.open }" |
| 18 | + item-rd |
| 19 | + min-h="32px" |
| 20 | + py-1 |
| 21 | + > |
| 22 | + <q-item-section |
| 23 | + avatar |
| 24 | + min-w-0 |
| 25 | + > |
| 26 | + <q-icon |
| 27 | + size="16px" |
| 28 | + name="sym_o_code" |
| 29 | + /> |
| 30 | + </q-item-section> |
| 31 | + <q-item-section> |
| 32 | + {{ artifact.name }} |
| 33 | + </q-item-section> |
| 34 | + <q-item-section side> |
| 35 | + <q-btn |
| 36 | + v-if="artifact.open" |
| 37 | + flat |
| 38 | + dense |
| 39 | + round |
| 40 | + icon="sym_o_close" |
| 41 | + title="关闭" |
| 42 | + size="sm" |
| 43 | + @click.prevent.stop="closeArtifact(artifact)" |
| 44 | + /> |
| 45 | + </q-item-section> |
| 46 | + <q-menu |
| 47 | + context-menu |
| 48 | + > |
| 49 | + <q-list style="min-width: 100px"> |
| 50 | + <menu-item |
| 51 | + icon="sym_o_edit" |
| 52 | + label="重命名" |
| 53 | + @click="renameItem(artifact)" |
| 54 | + /> |
| 55 | + <menu-item |
| 56 | + icon="sym_o_move_item" |
| 57 | + label="移动至" |
| 58 | + @click="moveItem(artifact)" |
| 59 | + /> |
| 60 | + <menu-item |
| 61 | + icon="sym_o_delete" |
| 62 | + label="删除" |
| 63 | + @click="deleteItem(artifact)" |
| 64 | + hover:text-err |
| 65 | + /> |
| 66 | + </q-list> |
| 67 | + </q-menu> |
| 68 | + </q-item> |
| 69 | + </q-list> |
| 70 | +</template> |
| 71 | + |
| 72 | +<script setup lang="ts"> |
| 73 | +import { useQuasar } from 'quasar' |
| 74 | +import { db } from 'src/utils/db' |
| 75 | +import { caselessIncludes } from 'src/utils/functions' |
| 76 | +import { Artifact } from 'src/utils/types' |
| 77 | +import { dialogOptions } from 'src/utils/values' |
| 78 | +import { computed, inject, ref, Ref } from 'vue' |
| 79 | +import SelectWorkspaceDialog from './SelectWorkspaceDialog.vue' |
| 80 | +import MenuItem from './MenuItem.vue' |
| 81 | +import { useCloseArtifact } from 'src/composables/close-artifact' |
| 82 | +import { useRouter } from 'vue-router' |
| 83 | +
|
| 84 | +const artifacts: Ref<Artifact[]> = inject('artifacts') |
| 85 | +const filter = ref(null) |
| 86 | +const filteredArtifacts = computed(() => { |
| 87 | + return artifacts.value.filter(d => !filter.value || caselessIncludes(d.name, filter.value)).reverse() |
| 88 | +}) |
| 89 | +
|
| 90 | +const $q = useQuasar() |
| 91 | +
|
| 92 | +function renameItem({ id, name }) { |
| 93 | + $q.dialog({ |
| 94 | + title: '重命名', |
| 95 | + prompt: { |
| 96 | + model: name, |
| 97 | + type: 'text', |
| 98 | + label: '名称', |
| 99 | + isValid: v => v.trim() && v !== name |
| 100 | + }, |
| 101 | + cancel: true, |
| 102 | + ...dialogOptions |
| 103 | + }).onOk(newName => { |
| 104 | + db.canvases.update(id, { name: newName.trim() }) |
| 105 | + }) |
| 106 | +} |
| 107 | +function moveItem({ id }) { |
| 108 | + $q.dialog({ |
| 109 | + component: SelectWorkspaceDialog, |
| 110 | + componentProps: { |
| 111 | + accept: 'workspace' |
| 112 | + } |
| 113 | + }).onOk(workspaceId => { |
| 114 | + db.canvases.update(id, { workspaceId }) |
| 115 | + }) |
| 116 | +} |
| 117 | +function deleteItem({ id, name }) { |
| 118 | + $q.dialog({ |
| 119 | + title: '删除 Artifact', |
| 120 | + message: `确定要删除 Artifact「${name}」吗?`, |
| 121 | + cancel: true, |
| 122 | + ok: { |
| 123 | + label: '删除', |
| 124 | + color: 'err', |
| 125 | + flat: true |
| 126 | + }, |
| 127 | + ...dialogOptions |
| 128 | + }).onOk(() => { |
| 129 | + db.canvases.delete(id) |
| 130 | + }) |
| 131 | +} |
| 132 | +const router = useRouter() |
| 133 | +function openArtifact({ id, open }) { |
| 134 | + !open && db.canvases.update(id, { open: true }) |
| 135 | + router.push({ query: { artifactId: id } }) |
| 136 | +} |
| 137 | +const { closeArtifact } = useCloseArtifact() |
| 138 | +</script> |
0 commit comments