<template>
	<div class="layout-padding">
		<div class="layout-padding-auto layout-padding-view">
			<el-row class="ml10" v-show="showSearch">
				<el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList" ref="queryRef">
					<el-form-item label="关键字" prop="logType">
						<el-input placeholder="请输入关键字"  v-model="state.queryForm.queryIPName" />
					</el-form-item>
          <el-form-item label="IP" prop="logType">
						<el-input placeholder="请输入IP"  v-model="state.queryForm.queryIPName" />
					</el-form-item>
					<el-form-item label="域名" prop="logType">
						<el-input placeholder="请输入域名"  v-model="state.queryForm.queryIPName" />
					</el-form-item>
					<el-form-item>
						<el-button @click="getDataList" type="primary">查询</el-button>
						<el-button @click="resetQuery" icon="Refresh">重置</el-button>
					</el-form-item>
				</el-form>
			</el-row>
		
			<el-table
				:data="tableData"
				v-loading="state.loading"
				border
				:cell-style="tableStyle.cellStyle"
				:header-cell-style="tableStyle.headerCellStyle"
			>
				<el-table-column label="规则名称" prop="title" show-overflow-tooltip></el-table-column>
				<el-table-column label="关键字" prop="keywords" show-overflow-tooltip></el-table-column>
				<el-table-column label="IP" prop="ip" show-overflow-tooltip></el-table-column>
				<el-table-column label="域名" prop="domain" show-overflow-tooltip width="200"></el-table-column>
				<el-table-column label="触发规则" prop="rules" show-overflow-tooltip width="200"></el-table-column>
				<el-table-column label="备注" prop="createBy" show-overflow-tooltip width="200"></el-table-column>
				<el-table-column label="操作" width="150">
					<template #default="scope">
						<el-button @click="openEdit({})" size="small" text type="primary">
							新增
						</el-button>
						<el-button @click="openEdit(scope.row)" size="small" text type="primary">
							编辑
						</el-button>
					</template>
				</el-table-column>
			</el-table>
      <Edit v-model:open="open" @close="open = false" />
			<pagination @current-change="currentChangeHandle" @size-change="sizeChangeHandle" v-bind="state.pagination"> </pagination>
		</div>
	</div>
</template>

<script lang="ts" setup>
import { BasicTableProps, useTable } from '/@/hooks/table';
import { delObj, pageList } from '/@/api/admin/log';
import { useI18n } from 'vue-i18n';


const Edit = defineAsyncComponent(() => import('./components/Edit.vue'));

const open = ref(false);
const rowData = ref({});
const { t } = useI18n();

// 定义变量内容
const queryRef = ref();
const showSearch = ref(true);


const state: BasicTableProps = reactive<BasicTableProps>({
	queryForm: {
		logType: '',
		createTime: '',
	},
	selectObjs: [],
	pageList: pageList,
	descs: ['create_time'],
});

const tableData = ref([
  {
    title: '系统安全检测',
    keywords: '安全,检测,漏洞',
    ip: '192.168.1.2',
    domain: 'www.google.com',
    rules: '基础安全扫描规则',
    createBy: '张三',
    createTime: '2021-02-15 09:30:00'
  },
  {
    title: '性能压力测试',
    keywords: '性能,压力,并发',
    ip: '192.168.1.3',
    domain: 'www.github.com',
    rules: '高并发压力测试规则',
    createBy: '李四',
    createTime: '2021-03-20 14:15:00'
  },
  {
    title: '接口兼容性测试',
    keywords: '接口,兼容,API',
    ip: '192.168.1.4',
    domain: 'www.api.com',
    rules: '接口版本兼容规则',
    createBy: '王五',
    createTime: '2021-04-05 10:45:00'
  },
  {
    title: '数据备份验证',
    keywords: '数据,备份,验证',
    ip: '192.168.1.5',
    domain: 'www.backup.com',
    rules: '数据完整性校验规则',
    createBy: '赵六',
    createTime: '2021-05-18 16:20:00'
  },
  {
    title: '用户体验测试',
    keywords: '用户,体验,UI',
    ip: '192.168.1.6',
    domain: 'www.ux.com',
    rules: '界面交互测试规则',
    createBy: '孙七',
    createTime: '2021-06-30 11:10:00'
  },
  {
    title: '权限控制测试',
    keywords: '权限,控制,安全',
    ip: '192.168.1.7',
    domain: 'www.auth.com',
    rules: 'RBAC权限验证规则',
    createBy: '周八',
    createTime: '2021-07-12 15:50:00'
  },
  {
    title: '数据库性能测试',
    keywords: '数据库,性能,查询',
    ip: '192.168.1.8',
    domain: 'www.db.com',
    rules: 'SQL执行效率测试规则',
    createBy: '吴九',
    createTime: '2021-08-25 08:35:00'
  },
  {
    title: '移动端适配测试',
    keywords: '移动,适配,响应式',
    ip: '192.168.1.9',
    domain: 'www.mobile.com',
    rules: '多终端适配测试规则',
    createBy: '郑十',
    createTime: '2021-09-10 13:25:00'
  },
  {
    title: '日志分析测试',
    keywords: '日志,分析,监控',
    ip: '192.168.1.10',
    domain: 'www.log.com',
    rules: '日志完整性检查规则',
    createBy: '钱十一',
    createTime: '2021-10-01 17:40:00'
  },
  {
    title: '缓存机制测试',
    keywords: '缓存,机制,性能',
    ip: '192.168.1.11',
    domain: 'www.cache.com',
    rules: '缓存有效性验证规则',
    createBy: '孙十二',
    createTime: '2021-11-15 10:15:00'
  }
]);

//  table hook
const { downBlobFile, getDataList, currentChangeHandle, sortChangeHandle, sizeChangeHandle, tableStyle } = useTable(state);

// 清空搜索条件
const resetQuery = () => {
	queryRef.value?.resetFields();
	getDataList();
};

// 导出excel
const exportExcel = () => {
	downBlobFile('/admin/log/export', state.queryForm, 'log.xlsx');
};
const openEdit = (row: any) => {
  rowData.value = row;
  open.value = true;

}



</script>

<style lang="scss" scoped>
pre code.hljs {
	width: 65%;
}
</style>
