SourceDebug.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. try {
  40. await API.saveSource(store.currentSource);
  41. } catch (e) {
  42. store.debugFinish();
  43. throw e;
  44. }
  45. API.debug(
  46. store.currentSourceUrl,
  47. searchKey.value || store.searchKey,
  48. appendDebugMsg,
  49. store.debugFinish,
  50. );
  51. };
  52. const isBookSource = computed(() => {
  53. return /bookSource/i.test(window.location.href);
  54. });
  55. </script>
  56. <style lang="scss" scoped>
  57. :deep(#debug-text) {
  58. height: calc(100vh - 45px - 36px - 5px);
  59. }
  60. </style>