SourceJson.vue 919 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <el-input
  3. id="source-json"
  4. v-model="sourceString"
  5. type="textarea"
  6. placeholder="这里输出序列化的JSON数据,可直接导入'阅读'APP"
  7. :rows="30"
  8. @change="update"
  9. style="margin-bottom: 4px"
  10. ></el-input>
  11. </template>
  12. <script setup>
  13. import { useSourceStore } from "@/store";
  14. const store = useSourceStore();
  15. const sourceString = ref("");
  16. const update = async (string) => {
  17. try {
  18. store.changeEditTabSource(JSON.parse(string));
  19. } catch {
  20. ElMessage({
  21. message: "粘贴的源格式错误",
  22. type: "error",
  23. });
  24. }
  25. };
  26. watchEffect(async () => {
  27. let source = store.editTabSource;
  28. if (Object.keys(source).length > 0) {
  29. sourceString.value = JSON.stringify(source, null, 4);
  30. } else {
  31. sourceString.value = "";
  32. }
  33. });
  34. </script>
  35. <style scoped>
  36. :deep(.el-input) {
  37. width: 100%;
  38. }
  39. :deep(#source-json) {
  40. height: calc(100vh - 50px);
  41. }
  42. </style>