SkillManagement.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <script setup>
  2. import { ref, onMounted, onUnmounted } from 'vue'
  3. import { useRouter } from 'vue-router'
  4. import { NButton, NIcon, NSpin, NEmpty, NDialog, useDialog, useMessage } from 'naive-ui'
  5. import { AddOutline, ReloadOutline } from '@vicons/ionicons5'
  6. import { useSkillStore } from '../stores/skill'
  7. import SkillCard from '../components/skill/SkillCard.vue'
  8. import SkillUpload from '../components/skill/SkillUpload.vue'
  9. const router = useRouter()
  10. const skillStore = useSkillStore()
  11. const dialog = useDialog()
  12. const message = useMessage()
  13. const showUpload = ref(false)
  14. onMounted(() => {
  15. skillStore.init()
  16. })
  17. onUnmounted(() => {
  18. skillStore.destroy()
  19. })
  20. function handleRefresh() {
  21. skillStore.fetchSkills()
  22. }
  23. async function handleUpload(file) {
  24. try {
  25. await skillStore.createSkill(file)
  26. showUpload.value = false
  27. message.success('技能上传成功')
  28. } catch (err) {
  29. message.error(err.message || '上传失败')
  30. }
  31. }
  32. function handleEdit(skill) {
  33. router.push(`/skill/edit/${skill.folderName}`)
  34. }
  35. function handleDelete(skill) {
  36. dialog.warning({
  37. title: '确认删除',
  38. content: `确定要删除技能「${skill.translatedName || skill.name}」吗?此操作不可恢复。`,
  39. positiveText: '确认删除',
  40. negativeText: '取消',
  41. onPositiveClick: async () => {
  42. try {
  43. await skillStore.removeSkill(skill.folderName)
  44. message.success('删除成功')
  45. } catch (err) {
  46. message.error(err.message || '删除失败')
  47. }
  48. }
  49. })
  50. }
  51. </script>
  52. <template>
  53. <div class="skill-management">
  54. <!-- 操作栏 -->
  55. <div class="toolbar">
  56. <div class="toolbar-left">
  57. <span class="skill-count">
  58. 共 <span class="count-num">{{ skillStore.skills.length }}</span> 个技能
  59. </span>
  60. </div>
  61. <div class="toolbar-right">
  62. <n-button quaternary @click="handleRefresh" :loading="skillStore.loading">
  63. <template #icon>
  64. <n-icon><ReloadOutline /></n-icon>
  65. </template>
  66. 刷新
  67. </n-button>
  68. <n-button type="primary" @click="showUpload = true">
  69. <template #icon>
  70. <n-icon><AddOutline /></n-icon>
  71. </template>
  72. 新增技能
  73. </n-button>
  74. </div>
  75. </div>
  76. <!-- 加载状态 -->
  77. <div v-if="skillStore.loading && skillStore.skills.length === 0" class="loading-area">
  78. <n-spin size="large" />
  79. <p class="loading-text">正在加载技能列表...</p>
  80. </div>
  81. <!-- 空状态 -->
  82. <div v-else-if="skillStore.skills.length === 0" class="empty-area">
  83. <div class="empty-illustration">
  84. <svg width="120" height="120" viewBox="0 0 120 120" fill="none" xmlns="http://www.w3.org/2000/svg">
  85. <rect x="20" y="30" width="80" height="60" rx="8" stroke="rgba(56, 189, 248, 0.15)" stroke-width="2" fill="none"/>
  86. <path d="M45 55H75" stroke="rgba(56, 189, 248, 0.2)" stroke-width="2" stroke-linecap="round"/>
  87. <path d="M45 65H65" stroke="rgba(56, 189, 248, 0.15)" stroke-width="2" stroke-linecap="round"/>
  88. <circle cx="60" cy="60" r="30" stroke="rgba(37, 99, 235, 0.1)" stroke-width="1" fill="none"/>
  89. </svg>
  90. </div>
  91. <p class="empty-title">暂无技能</p>
  92. <p class="empty-desc">点击「新增技能」上传您的第一个 Skill</p>
  93. <n-button type="primary" @click="showUpload = true" style="margin-top: 16px">
  94. <template #icon>
  95. <n-icon><AddOutline /></n-icon>
  96. </template>
  97. 新增技能
  98. </n-button>
  99. </div>
  100. <!-- 卡片网格 -->
  101. <div v-else class="skill-grid">
  102. <SkillCard
  103. v-for="(skill, index) in skillStore.skills"
  104. :key="skill.folderName"
  105. :skill="skill"
  106. :style="{ animationDelay: `${index * 60}ms` }"
  107. class="fade-in"
  108. @edit="handleEdit"
  109. @delete="handleDelete"
  110. />
  111. </div>
  112. <!-- 上传弹窗 -->
  113. <SkillUpload
  114. v-model:show="showUpload"
  115. :uploading="skillStore.uploading"
  116. :progress="skillStore.uploadProgress"
  117. @upload="handleUpload"
  118. />
  119. </div>
  120. </template>
  121. <style scoped>
  122. .skill-management {
  123. min-height: 100%;
  124. }
  125. /* 操作栏 */
  126. .toolbar {
  127. display: flex;
  128. align-items: center;
  129. justify-content: space-between;
  130. margin-bottom: 28px;
  131. }
  132. .skill-count {
  133. font-size: 14px;
  134. color: var(--text-secondary);
  135. }
  136. .count-num {
  137. color: var(--color-accent);
  138. font-weight: 600;
  139. }
  140. .toolbar-right {
  141. display: flex;
  142. gap: 8px;
  143. }
  144. /* 加载状态 */
  145. .loading-area {
  146. display: flex;
  147. flex-direction: column;
  148. align-items: center;
  149. justify-content: center;
  150. padding: 80px 0;
  151. gap: 16px;
  152. }
  153. .loading-text {
  154. font-size: 14px;
  155. color: var(--text-tertiary);
  156. }
  157. /* 空状态 */
  158. .empty-area {
  159. display: flex;
  160. flex-direction: column;
  161. align-items: center;
  162. justify-content: center;
  163. padding: 80px 0;
  164. }
  165. .empty-illustration {
  166. margin-bottom: 20px;
  167. opacity: 0.6;
  168. }
  169. .empty-title {
  170. font-size: 16px;
  171. font-weight: 500;
  172. color: var(--text-secondary);
  173. margin-bottom: 8px;
  174. }
  175. .empty-desc {
  176. font-size: 13px;
  177. color: var(--text-muted);
  178. }
  179. /* 卡片网格 */
  180. .skill-grid {
  181. display: grid;
  182. grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  183. gap: 20px;
  184. }
  185. </style>