SearchTable.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <div>
  3. <header class="DocSearch-SearchBar" style="padding: 0">
  4. <form class="DocSearch-Form searchinput">
  5. <input class="DocSearch-Input" v-model="filterText" placeholder="Filter name..." @input="doFilter" />
  6. </form>
  7. </header>
  8. <table>
  9. <thead>
  10. <tr>
  11. <th>Extension Name</th>
  12. <th>Linux</th>
  13. <th>macOS</th>
  14. <th>FreeBSD</th>
  15. <th>Windows</th>
  16. </tr>
  17. </thead>
  18. <tbody>
  19. <tr v-for="item in filterData">
  20. <td v-if="!item.notes">{{ item.name }}</td>
  21. <td v-else>
  22. <a :href="'./extension-notes.html#' + item.name">{{ item.name }}</a>
  23. </td>
  24. <td>{{ item.linux }}</td>
  25. <td>{{ item.macos }}</td>
  26. <td>{{ item.freebsd }}</td>
  27. <td>{{ item.windows }}</td>
  28. </tr>
  29. </tbody>
  30. </table>
  31. <div v-if="filterData.length === 0" style="margin: 0 4px 20px 4px; color: var(--vp-c-text-2); font-size: 14px">
  32. No result, please try another keyword.
  33. </div>
  34. </div>
  35. </template>
  36. <script>
  37. export default {
  38. name: "SearchTable"
  39. }
  40. </script>
  41. <script setup>
  42. import {ref} from "vue";
  43. import ext from '../../../config/ext.json';
  44. // 将 ext 转换为列表,方便后续操作
  45. const data = ref([]);
  46. for (const [name, item] of Object.entries(ext)) {
  47. data.value.push({
  48. name,
  49. linux: item.support?.Linux === undefined ? 'yes' : (item.support?.Linux === 'wip' ? '' : item.support?.Linux),
  50. macos: item.support?.Darwin === undefined ? 'yes' : (item.support?.Darwin === 'wip' ? '' : item.support?.Darwin),
  51. freebsd: item.support?.BSD === undefined ? 'yes' : (item.support?.BSD === 'wip' ? '' : item.support?.BSD),
  52. windows: item.support?.Windows === undefined ? 'yes' : (item.support?.Windows === 'wip' ? '' : item.support?.Windows),
  53. notes: item.notes === true,
  54. });
  55. }
  56. const filterData = ref(data.value);
  57. const filterText = ref('');
  58. const doFilter = () => {
  59. if (filterText.value === '') {
  60. filterData.value = data.value;
  61. return;
  62. }
  63. filterData.value = data.value.filter(item => {
  64. return item.name.toLowerCase().includes(filterText.value.toLowerCase());
  65. });
  66. }
  67. </script>
  68. <style>
  69. .searchinput {
  70. border: 1px solid var(--vp-c-divider);
  71. }
  72. </style>