detail.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <div class="system-edit-dic-container">
  3. <el-dialog title="数据记录" v-model="isShowDialog" width="75%">
  4. <el-form :model="ruleForm" ref="formRef" :rules="rules" size="default" label-width="110px">
  5. <el-form-item :label="item+':'" v-for="(item,index) in jData" >
  6. {{jsonsData[index]}}
  7. </el-form-item>
  8. </el-form>
  9. </el-dialog>
  10. </div>
  11. </template>
  12. <script lang="ts">
  13. import { reactive, toRefs, defineComponent,ref, unref } from 'vue';
  14. import api from '/@/api/datahub';
  15. import {ElMessage} from "element-plus";
  16. interface DicState {
  17. isShowDialog: boolean;
  18. }
  19. export default defineComponent({
  20. name: 'deviceEditPro',
  21. setup(prop,{emit}) {
  22. const formRef = ref<HTMLElement | null>(null);
  23. const state = reactive<DicState>({
  24. isShowDialog: false,
  25. jsonsData:[],
  26. jData:[]
  27. });
  28. // 打开弹窗
  29. const openDialog = (row: RuleFormState|null) => {
  30. resetForm();
  31. if (row){
  32. api.template.getdata(row.id).then((res:any)=>{
  33. const jsonData=JSON.parse(res.data);
  34. state.jData=Object.keys(jsonData);
  35. console.log(state.jData);
  36. state.jData.forEach((item, index) => {
  37. state.jsonsData[index] = jsonData[item];
  38. });
  39. console.log(state.jsonsData);
  40. //state.ruleForm = res.data.dictType
  41. })
  42. state.ruleForm = row;
  43. }
  44. state.isShowDialog = true;
  45. };
  46. const resetForm = ()=>{
  47. state.jsonsData=[];
  48. state.jData=[];
  49. };
  50. // 关闭弹窗
  51. const closeDialog = () => {
  52. state.isShowDialog = false;
  53. };
  54. // 取消
  55. const onCancel = () => {
  56. closeDialog();
  57. };
  58. return {
  59. openDialog,
  60. closeDialog,
  61. onCancel,
  62. formRef,
  63. ...toRefs(state),
  64. };
  65. },
  66. });
  67. </script>