Browse Source

style(types): 修改ts报错

Yi 1 year ago
parent
commit
c1cb95b990

+ 29 - 7
src/typings/basic.d.ts

@@ -24,15 +24,26 @@ declare namespace RowField {
     show_line: number;
   }
 }
-
 declare namespace EventSelectBox {
   interface Data {
-    cowFieldData: ApiBackground.BasicCowField[] | null;
-    isRequired: ApiBackground.BasicSelectValue[] | null;
-    dataSource: ApiBackground.BasicSelectValue[] | null;
-    isList: ApiBackground.BasicSelectValue[] | null;
-    isDetails: ApiBackground.BasicSelectValue[] | null;
-    showLine: ApiBackground.BasicSelectValue[] | null;
+    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+    // @ts-ignore
+    cowFieldData: any | undefined;
+    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+    // @ts-ignore
+    isRequired: any | undefined;
+    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+    // @ts-ignore
+    dataSource: any | undefined;
+    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+    // @ts-ignore
+    isList: any | undefined;
+    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+    // @ts-ignore
+    isDetails: any | undefined;
+    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+    // @ts-ignore
+    showLine: any | undefined;
   }
 }
 
@@ -60,3 +71,14 @@ declare namespace IndicatorsSelectBox {
     startTime: ApiBackground.BasicSelectValue[] | null;
   }
 }
+
+declare namespace RowSettingEvent {
+  interface Data {
+    event_name: string;
+    field_name: string;
+    impact_mode: number;
+    impact_value: string;
+    where_type: number;
+    condition: [];
+  }
+}

+ 2 - 0
src/views/background/event/components/select-box.vue

@@ -1,3 +1,4 @@
+<!--
 <template>
   <n-select
     v-model:value="selectValue"
@@ -41,3 +42,4 @@ export default defineComponent({
   }
 });
 </script>
+-->

+ 14 - 16
src/views/background/event/components/table-action-modal.vue

@@ -29,11 +29,10 @@
 <script setup lang="ts">
 import { ref, computed, reactive, watch, h } from 'vue';
 import type { FormInst, FormItemRule, DataTableColumns, PaginationProps } from 'naive-ui';
-import { NButton, NTag, NInput } from 'naive-ui';
+import { NButton, NTag, NInput, NSelect } from 'naive-ui';
 import { EditSelectBoxDataSource, EditSelectBoxIsShow, EditSelectBoxShowLine, EventIsShowOptions } from '@/constants';
 import { createRequiredFormRule } from '@/utils';
 import { basicEventColumnName, fetchEventAdd, fetchEventEdit } from '@/service/api/event';
-import SelectBox from './select-box.vue';
 export interface Props {
   /** 弹窗可见性 */
   visible: boolean;
@@ -205,8 +204,8 @@ const createColumns = (): DataTableColumns<RowField.Data> => [
     maxWidth: 300,
     // eslint-disable-next-line @typescript-eslint/no-unused-vars
     render(row, index) {
-      return h(SelectBox, {
-        fieldOptions: selectBoxData.cowFieldData,
+      return h(NSelect, {
+        options: selectBoxData.cowFieldData,
         value: tableData.value[index].column_name,
         onUpdateTableValue(value: string) {
           tableData.value[index].column_name = value;
@@ -220,8 +219,8 @@ const createColumns = (): DataTableColumns<RowField.Data> => [
     maxWidth: 100,
     // eslint-disable-next-line @typescript-eslint/no-unused-vars
     render(row, index) {
-      return h(SelectBox, {
-        fieldOptions: selectBoxData.isRequired,
+      return h(NSelect, {
+        options: selectBoxData.isRequired,
         value: tableData.value[index].is_required,
         onUpdateTableValue(value: number) {
           tableData.value[index].is_required = value;
@@ -235,8 +234,8 @@ const createColumns = (): DataTableColumns<RowField.Data> => [
     maxWidth: 200,
     // eslint-disable-next-line @typescript-eslint/no-unused-vars
     render(row, index) {
-      return h(SelectBox, {
-        fieldOptions: selectBoxData.dataSource,
+      return h(NSelect, {
+        options: selectBoxData.dataSource,
         value: tableData.value[index].data_source,
         onUpdateTableValue(value: number) {
           tableData.value[index].data_source = value;
@@ -250,8 +249,8 @@ const createColumns = (): DataTableColumns<RowField.Data> => [
     maxWidth: 200,
     // eslint-disable-next-line @typescript-eslint/no-unused-vars
     render(row, index) {
-      return h(SelectBox, {
-        fieldOptions: selectBoxData.isList,
+      return h(NSelect, {
+        options: selectBoxData.isList,
         value: tableData.value[index].is_list,
         onUpdateTableValue(value: number) {
           tableData.value[index].is_list = value;
@@ -265,10 +264,10 @@ const createColumns = (): DataTableColumns<RowField.Data> => [
     maxWidth: 200,
     // eslint-disable-next-line @typescript-eslint/no-unused-vars
     render(row, index) {
-      return h(SelectBox, {
-        fieldOptions: selectBoxData.isDetails,
+      return h(NSelect, {
+        options: selectBoxData.isDetails,
         value: tableData.value[index].is_details,
-        onUpdateTableValue(value: number) {
+        onUpdateValue(value: number) {
           tableData.value[index].is_details = value;
         }
       });
@@ -280,8 +279,8 @@ const createColumns = (): DataTableColumns<RowField.Data> => [
     maxWidth: 200,
     // eslint-disable-next-line @typescript-eslint/no-unused-vars
     render(row, index) {
-      return h(SelectBox, {
-        fieldOptions: selectBoxData.showLine,
+      return h(NSelect, {
+        options: selectBoxData.showLine,
         value: tableData.value[index].show_line,
         onUpdateValue(value: number) {
           tableData.value[index].show_line = value;
@@ -298,7 +297,6 @@ const createColumns = (): DataTableColumns<RowField.Data> => [
         h(
           NButton,
           {
-            // 可在里面写按钮样式
             text: true,
             style: { marginRight: '10px', color: 'red' },
             onClick: () => deleteData(index) // 点击按钮后的回调

+ 0 - 1
src/views/background/event/components/table-condition-modal.vue

@@ -11,7 +11,6 @@
         <n-button type="primary" @click="addConditionGroup">添加条件组</n-button>
       </n-space>
       <n-data-table :columns="columns" :data="data" style="margin-top: 20px" />
-      <!-- <pre>{{ JSON.stringify(data, null, 2) }}</pre> -->
     </n-form>
   </n-modal>
 </template>

+ 274 - 0
src/views/background/event/components/table-setting-modal.vue

@@ -0,0 +1,274 @@
+<template>
+  <n-modal v-model:show="settingVisible" preset="card" title="事件影响设置" style="width: 70%">
+    <n-form ref="formRef" label-placement="left" :label-width="80" :model="formModel">
+      <n-space style="display: flex; flex-direction: column">
+        <n-button type="primary" @click="addEventSetting">添加事件</n-button>
+        <n-data-table :columns="columns" :data="tableData" />
+      </n-space>
+      <n-space class="w-full pt-16px" :size="25" justify="end">
+        <n-button class="w-72px" @click="closeModal">取消</n-button>
+        <n-button class="w-72px" type="primary" @click="handleSubmit">保持</n-button>
+      </n-space>
+    </n-form>
+  </n-modal>
+</template>
+
+<script setup lang="ts">
+import { computed, h, reactive, ref, watch } from 'vue';
+import type { FormInst, DataTableColumns } from 'naive-ui';
+import { NButton, NSelect, NTag, NSpace } from 'naive-ui';
+export interface Props {
+  /** 弹窗可见性 */
+  settingVisible: boolean;
+  /**
+   * 弹窗类型
+   * add: 新增
+   * edit: 编辑
+   */
+  type?: 'add' | 'edit';
+  /** 编辑的表格行数据 */
+  editData?: BackgroundEvent.Event | null;
+}
+
+export type ModalSettingType = NonNullable<Props['type']>;
+
+defineOptions({ name: 'TableSettingModal' });
+
+const createColumns = (): DataTableColumns<RowField.Data> => [
+  {
+    title: '序号',
+    key: 'index',
+    // eslint-disable-next-line @typescript-eslint/no-unused-vars
+    render(row, index) {
+      return h(
+        NTag,
+        {
+          style: {
+            marginRight: '6px',
+            background: 'none',
+            color: 'rgb(31, 34, 37)'
+          },
+          type: 'info',
+          bordered: false
+        },
+        {
+          default: () => index + 1
+        }
+      );
+    }
+  },
+  {
+    title: '选择事件',
+    key: 'columnName',
+    maxWidth: 300,
+    // eslint-disable-next-line @typescript-eslint/no-unused-vars
+    render(row, index) {
+      return h(NSelect, {
+        options: [
+          { label: 'OK', value: '1' },
+          { label: 'No', value: '2' }
+        ],
+        // value: tableData.value[index].column_name,
+        onUpdateTableValue(value: string) {
+          console.log('选择事件', value);
+        }
+      });
+    }
+  },
+  {
+    title: '选择字段',
+    key: 'isRequired',
+    maxWidth: 100,
+    // eslint-disable-next-line @typescript-eslint/no-unused-vars
+    render(row, index) {
+      return h(NSelect, {
+        options: [
+          { label: 'OK', value: '1' },
+          { label: 'No', value: '2' }
+        ],
+        // value: tableData.value[index].column_name,
+        onUpdateTableValue(value: string) {
+          console.log('选择事件', value);
+        }
+      });
+    }
+  },
+  {
+    title: '影响方式',
+    key: 'dataSource',
+    maxWidth: 200,
+    // eslint-disable-next-line @typescript-eslint/no-unused-vars
+    render(row, index) {
+      return h(NSelect, {
+        options: [
+          { label: 'OK', value: '1' },
+          { label: 'No', value: '2' }
+        ],
+        // value: tableData.value[index].column_name,
+        onUpdateTableValue(value: string) {
+          console.log('选择事件', value);
+        }
+      });
+    }
+  },
+  {
+    title: '条件类型',
+    key: 'isList',
+    maxWidth: 200,
+    // eslint-disable-next-line @typescript-eslint/no-unused-vars
+    render(row, index) {
+      return h(NSelect, {
+        options: [
+          { label: 'OK', value: '1' },
+          { label: 'No', value: '2' }
+        ],
+        // value: tableData.value[index].column_name,
+        onUpdateTableValue(value: string) {
+          console.log('选择事件', value);
+        }
+      });
+    }
+  },
+  {
+    title: '满足条件',
+    key: 'isDetails',
+    maxWidth: 200,
+    // eslint-disable-next-line @typescript-eslint/no-unused-vars
+    render(row, index) {
+      return h(NSelect, {
+        options: [
+          { label: 'OK', value: '1' },
+          { label: 'No', value: '2' }
+        ],
+        // value: tableData.value[index].column_name,
+        onUpdateTableValue(value: string) {
+          console.log('选择事件', value);
+        }
+      });
+    }
+  },
+  {
+    title: '操作',
+    key: 'actions',
+    // eslint-disable-next-line @typescript-eslint/no-unused-vars
+    render(row, index) {
+      return [
+        h(
+          NButton,
+          {
+            type: 'info',
+            size: 'small',
+            onClick: () => editData(index) // 点击按钮后的回调
+          },
+          { default: () => '编辑' } // 按钮显示名称
+        ),
+        h(
+          NButton,
+          {
+            type: 'error',
+            size: 'small',
+            onClick: () => deleteData(index) // 点击按钮后的回调
+          },
+          { default: () => '删除' } // 按钮显示名称
+        )
+      ];
+    }
+  }
+];
+
+const columns = ref(createColumns());
+
+const createData = (): RowSettingEvent.Data[] => [
+  {
+    event_name: '',
+    field_name: '',
+    impact_mode: 1,
+    impact_value: '',
+    where_type: 1,
+    condition: []
+  }
+];
+
+const tableData = ref(createData());
+
+interface Emits {
+  (e: 'update:settingVisible', visible: boolean): void;
+}
+
+const emit = defineEmits<Emits>();
+
+const props = withDefaults(defineProps<Props>(), {
+  type: 'add',
+  editData: null
+});
+
+const settingVisible = computed({
+  get() {
+    return props.settingVisible;
+  },
+  set(visible) {
+    emit('update:settingVisible', visible);
+  }
+});
+
+const closeModal = () => {
+  settingVisible.value = false;
+};
+
+function handleSubmit() {
+  console.log('handleSubmit');
+}
+
+const formRef = ref<HTMLElement & FormInst>();
+type FormModel = Pick<BackgroundEvent.Event, 'name'>;
+
+const formModel = reactive<FormModel>(createDefaultFormModel());
+function handleUpdateFormModel(model: Partial<FormModel>) {
+  Object.assign(formModel, model);
+}
+
+function createDefaultFormModel(): FormModel {
+  return {
+    name: ''
+  };
+}
+
+function deleteData(index: number) {
+  console.log('==index=====', index);
+}
+
+function editData(index: number) {
+  console.log('==index=====', index);
+}
+
+function handleUpdateFormModelByModalType() {
+  const handlers: Record<ModalSettingType, () => void> = {
+    add: () => {
+      const defaultFormModel = createDefaultFormModel();
+      handleUpdateFormModel(defaultFormModel);
+    },
+    edit: () => {
+      if (props.editData) {
+        handleUpdateFormModel(props.editData);
+      }
+    }
+  };
+
+  handlers[props.type]();
+}
+
+// 添加条件
+async function addEventSetting() {
+  tableData.value.push(createData()[0]);
+}
+
+watch(
+  () => props.settingVisible,
+  newValue => {
+    if (newValue) {
+      handleUpdateFormModelByModalType();
+    }
+  }
+);
+</script>
+<style scoped></style>

+ 0 - 119
src/views/background/event/components/table-setting-model.vue

@@ -1,119 +0,0 @@
-<template>
-  <n-modal v-model:show="modalVisible" preset="card" :title="title" style="width: 70%">
-    <n-form ref="formRef" label-placement="left" :label-width="80" :model="formModel" :rules="rules">
-      <n-space style="display: flex; flex-direction: column">
-        <n-button type="primary" @click="addEventSetting">添加事件字段</n-button>
-        <n-data-table :columns="columns" :data="tableData" :pagination="pagination" />
-      </n-space>
-    </n-form>
-  </n-modal>
-</template>
-
-<script setup lang="ts">
-import { computed, reactive, ref, watch } from 'vue';
-import type { FormInst } from 'naive-ui';
-export interface Props {
-  /** 弹窗可见性 */
-  settingVisible: boolean;
-  /**
-   * 弹窗类型
-   * add: 新增
-   * edit: 编辑
-   */
-  type?: 'add' | 'edit';
-  /** 编辑的表格行数据 */
-  editData?: BackgroundEvent.Event | null;
-}
-
-export type ModalSettingType = NonNullable<Props['type']>;
-
-defineOptions({ name: 'TableSettingModal' });
-
-interface Emits {
-  (e: 'update:settingVisible', visible: boolean): void;
-}
-
-const emit = defineEmits<Emits>();
-
-const props = withDefaults(defineProps<Props>(), {
-  type: 'add',
-  editData: null
-});
-
-const modalVisible = computed({
-  get() {
-    return props.settingVisible;
-  },
-  set(visible) {
-    emit('update:settingVisible', visible);
-  }
-});
-const titles: Record<ModalSettingType, string> = {
-  add: '添加事件',
-  edit: '编辑事件'
-};
-
-const title = computed(() => {
-  return titles[props.type];
-});
-
-const settingVisible = computed({
-  get() {
-    return props.settingVisible;
-  },
-  set(visible) {
-    emit('update:settingVisible', visible);
-  }
-});
-
-const closeModal = () => {
-  settingVisible.value = false;
-};
-
-const formRef = ref<HTMLElement & FormInst>();
-type FormModel = Pick<BackgroundEvent.Event, 'name'>;
-
-const formModel = reactive<FormModel>(createDefaultFormModel());
-function handleUpdateFormModel(model: Partial<FormModel>) {
-  Object.assign(formModel, model);
-}
-
-function createDefaultFormModel(): FormModel {
-  return {
-    name: ''
-  };
-}
-
-function handleUpdateFormModelByModalType() {
-  const handlers: Record<ModalSettingType, () => void> = {
-    add: () => {
-      const defaultFormModel = createDefaultFormModel();
-      handleUpdateFormModel(defaultFormModel);
-    },
-    edit: () => {
-      if (props.editData) {
-        handleUpdateFormModel(props.editData);
-      }
-    }
-  };
-
-  handlers[props.type]();
-}
-
-// 添加条件
-async function addEventSetting() {
-  await formRef.value?.validate();
-  window.$message?.success('添加成功!');
-  closeModal();
-}
-
-watch(
-  () => props.settingVisible,
-  newValue => {
-    if (newValue) {
-      handleUpdateFormModelByModalType();
-    }
-  }
-);
-</script>
-<style scoped></style>

+ 3 - 2
src/views/background/event/index.vue

@@ -30,7 +30,7 @@
         :type="modalConditionType"
         :edit-data="editData"
       />
-      <table-setting-modal v-model:settingVisible="settingVisible" :type="ModalSettingType" :edit-data="editData" />
+      <table-setting-modal v-model:settingVisible="settingVisible" :type="modalSettingType" :edit-data="editData" />
     </n-card>
   </div>
 </template>
@@ -45,9 +45,10 @@ import { useBoolean, useLoading } from '@/hooks';
 import { fetchEventDelete, fetchEventList } from '@/service/api/event';
 import type { ModalType } from './components/table-action-modal.vue';
 import type { ModalConditionType } from './components/table-condition-modal.vue';
-import TableSettingModal, { ModalSettingType } from './components/table-setting-model.vue';
+import type { ModalSettingType } from './components/table-setting-modal.vue';
 import TableActionModal from './components/table-action-modal.vue';
 import TableConditionModal from './components/table-condition-modal.vue';
+import TableSettingModal from './components/table-setting-modal.vue';
 
 const { loading, startLoading, endLoading } = useLoading(false);
 const { bool: visible, setTrue: openModal } = useBoolean();

+ 1 - 0
src/views/background/workflow/components/table-action-modal.vue

@@ -22,6 +22,7 @@
 </template>
 
 <script setup lang="ts">
+import { computed, ref, reactive, watch } from 'vue';
 import type { FormInst, FormItemRule } from 'naive-ui';
 import { EventIsShowOptions } from '@/constants';
 import { createRequiredFormRule } from '@/utils';