|
| 1 | +<template> |
| 2 | + <div class="app-container"> |
| 3 | + <doc-alert title="地区 & IP" url="https://doc.iocoder.cn/area-and-ip/" /> |
| 4 | + <!-- 操作工具栏 --> |
| 5 | + <el-row :gutter="10" class="mb8"> |
| 6 | + <el-col :span="1.5"> |
| 7 | + <XButton preIcon="fa:search" type="primary" @click="handleAdd" title="IP 查询" /> |
| 8 | + </el-col> |
| 9 | + </el-row> |
| 10 | + <!-- 列表 --> |
| 11 | + <el-table |
| 12 | + v-if="refreshTable" |
| 13 | + v-loading="loading" |
| 14 | + :data="list" |
| 15 | + row-key="id" |
| 16 | + :tree-props="{ children: 'children', hasChildren: 'hasChildren' }" |
| 17 | + > |
| 18 | + <el-table-column label="编号" prop="id" /> |
| 19 | + <el-table-column label="名字" prop="name" /> |
| 20 | + </el-table> |
| 21 | + <!-- <XTable ref="xGrid" @register="registerTable" show-overflow /> --> |
| 22 | + |
| 23 | + <!-- 对话框(添加 / 修改) --> |
| 24 | + <el-dialog title="IP 查询" v-model="open" width="500px" append-to-body> |
| 25 | + <el-form ref="formRef" :model="form" :rules="rules" label-width="80px"> |
| 26 | + <el-form-item label="IP" prop="ip"> |
| 27 | + <el-input v-model="form.ip" placeholder="请输入 IP 地址" /> |
| 28 | + </el-form-item> |
| 29 | + <el-form-item label="地址" prop="result"> |
| 30 | + <el-input v-model="form.result" readonly placeholder="展示查询 IP 结果" /> |
| 31 | + </el-form-item> |
| 32 | + </el-form> |
| 33 | + <template #footer> |
| 34 | + <el-button type="primary" @click="submitForm(formRef)">查 询</el-button> |
| 35 | + <el-button @click="cancel(formRef)">取 消</el-button> |
| 36 | + </template> |
| 37 | + </el-dialog> |
| 38 | + </div> |
| 39 | +</template> |
| 40 | + |
| 41 | +<script lang="ts" setup name="Area"> |
| 42 | +import * as areaApi from '@/api/system/area' |
| 43 | +import type { FormInstance } from 'element-plus' |
| 44 | +// import { allSchemas } from './area.data' |
| 45 | +// import { getAreaByIp, getAreaTree } from '@/api/system/area' |
| 46 | +// 遮罩层 |
| 47 | +const loading = ref(true) |
| 48 | +// 地区列表 |
| 49 | +const list = ref([]) |
| 50 | +// 弹出层标题 |
| 51 | +// const title = ref('') |
| 52 | +// 是否显示弹出层 |
| 53 | +const open = ref(false) |
| 54 | +// 重新渲染表格状态 |
| 55 | +const refreshTable = ref(true) |
| 56 | +// 表单参数 |
| 57 | +const form = ref({ |
| 58 | + ip: undefined, |
| 59 | + result: undefined |
| 60 | +}) |
| 61 | +const formRef = ref<FormInstance>() |
| 62 | +// 表单校验 |
| 63 | +const rules = ref({ |
| 64 | + ip: [{ required: true, message: 'IP 地址不能为控', trigger: 'blur' }] |
| 65 | +}) |
| 66 | +const message = useMessage() // 消息弹窗 |
| 67 | +
|
| 68 | +// const treeConfig = { |
| 69 | +// transform: true, |
| 70 | +// rowField: 'id', |
| 71 | +// parentField: 'id' |
| 72 | +// // expandAll: true |
| 73 | +// } |
| 74 | +
|
| 75 | +// const [registerTable, { reload }] = useXTable({ |
| 76 | +// allSchemas: allSchemas, |
| 77 | +// treeConfig: treeConfig, |
| 78 | +// getListApi: areaApi.getAreaTree |
| 79 | +// }) |
| 80 | +
|
| 81 | +/** 查询列表 */ |
| 82 | +const getList = async () => { |
| 83 | + loading.value = true |
| 84 | + const response = await areaApi.getAreaTree() |
| 85 | + list.value = response.data |
| 86 | + loading.value = false |
| 87 | +} |
| 88 | +/** 取消按钮 */ |
| 89 | +const cancel = (formEl: FormInstance | undefined) => { |
| 90 | + if (!formEl) return |
| 91 | + formEl.resetFields() |
| 92 | + open.value = false |
| 93 | + reset() |
| 94 | +} |
| 95 | +/** 表单重置 */ |
| 96 | +const reset = async () => { |
| 97 | + form.value = { |
| 98 | + ip: undefined, |
| 99 | + result: undefined |
| 100 | + } |
| 101 | + // await reload() |
| 102 | +} |
| 103 | +/** 新增按钮操作 */ |
| 104 | +const handleAdd = () => { |
| 105 | + open.value = true |
| 106 | + reset() |
| 107 | +} |
| 108 | +/** 提交按钮 */ |
| 109 | +const submitForm = async (formEl: FormInstance | undefined) => { |
| 110 | + if (!formEl) return |
| 111 | + await formEl.validate(async (valid, fields) => { |
| 112 | + if (valid) { |
| 113 | + console.log('submit!') |
| 114 | + const response = await areaApi.getAreaByIp(form.value.ip) |
| 115 | + message.success('查询成功') |
| 116 | + form.value.result = response.data |
| 117 | + } else { |
| 118 | + console.log('error submit!', fields) |
| 119 | + } |
| 120 | + }) |
| 121 | +} |
| 122 | +
|
| 123 | +onMounted(() => { |
| 124 | + getList() |
| 125 | +}) |
| 126 | +</script> |
0 commit comments