SourceDebug.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <el-input
  3. v-if="isBookSource"
  4. id="debug-key"
  5. v-model="searchKey"
  6. placeholder="搜索书名、作者"
  7. :prefix-icon="Search"
  8. style="padding-bottom: 4px"
  9. @keydown.enter="startDebug"
  10. />
  11. <el-input
  12. id="debug-text"
  13. v-model="printDebug"
  14. type="textarea"
  15. readonly
  16. rows="29"
  17. placeholder="这里用于输出调试信息"
  18. />
  19. </template>
  20. <script setup>
  21. import API from "@api";
  22. import { Search } from "@element-plus/icons-vue";
  23. const store = useSourceStore();
  24. const printDebug = ref("");
  25. const searchKey = ref("");
  26. watch(
  27. () => store.isDebuging,
  28. () => {
  29. if (store.isDebuging) startDebug();
  30. },
  31. );
  32. const appendDebugMsg = (msg) => {
  33. let debugDom = document.querySelector("#debug-text");
  34. debugDom.scrollTop = debugDom.scrollHeight;
  35. printDebug.value += msg + "\n";
  36. };
  37. const startDebug = async () => {
  38. printDebug.value = "";
  39. await API.saveSource(store.currentSource);
  40. API.debug(
  41. store.currentSourceUrl,
  42. searchKey.value || store.searchKey,
  43. appendDebugMsg,
  44. store.debugFinish,
  45. );
  46. };
  47. const isBookSource = computed(() => {
  48. return /bookSource/.test(window.location.href);
  49. });
  50. </script>
  51. <style lang="scss" scoped>
  52. :deep(#debug-text) {
  53. height: calc(100vh - 45px - 36px - 5px);
  54. }
  55. </style>