|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
import { ref } from 'vue'
|
|
|
|
|
|
import { usePageLoad } from '@/composables/usePageLoad'
|
|
|
|
|
|
import {
|
|
|
|
|
|
createUniversity,
|
|
|
|
|
|
deleteUniversity,
|
|
|
|
|
|
fetchUniversitiesList,
|
|
|
|
|
|
updateUniversity,
|
|
|
|
|
|
type UniversityRow,
|
|
|
|
|
|
} from '@/api/admin/assets'
|
|
|
|
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
|
|
|
|
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
const items = ref<UniversityRow[]>([])
|
|
|
|
|
|
const meta = ref({ current_page: 1, per_page: 20, total: 0 })
|
|
|
|
|
|
const page = ref(1)
|
|
|
|
|
|
|
|
|
|
|
|
const keyword = ref('')
|
|
|
|
|
|
const filterRegion = ref('')
|
|
|
|
|
|
|
|
|
|
|
|
const dialog = ref(false)
|
|
|
|
|
|
const editing = ref<UniversityRow | null>(null)
|
|
|
|
|
|
const form = ref({
|
|
|
|
|
|
name: '',
|
|
|
|
|
|
longitude: '',
|
|
|
|
|
|
latitude: '',
|
|
|
|
|
|
city: '',
|
|
|
|
|
|
province: '',
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const regionOptions = [
|
|
|
|
|
|
{ label: '上海高校', value: '上海' },
|
|
|
|
|
|
{ label: '苏州高校', value: '苏州' },
|
|
|
|
|
|
{ label: '浙江高校', value: '浙江' },
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
async function load() {
|
|
|
|
|
|
loading.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
const params: Record<string, unknown> = {
|
|
|
|
|
|
page: page.value,
|
|
|
|
|
|
page_size: meta.value.per_page,
|
|
|
|
|
|
}
|
|
|
|
|
|
if (keyword.value) params.keyword = keyword.value
|
|
|
|
|
|
if (filterRegion.value) params.region = filterRegion.value
|
|
|
|
|
|
const res = await fetchUniversitiesList(params)
|
|
|
|
|
|
items.value = res.items
|
|
|
|
|
|
meta.value = res.meta
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function resetFilters() {
|
|
|
|
|
|
keyword.value = ''
|
|
|
|
|
|
filterRegion.value = ''
|
|
|
|
|
|
page.value = 1
|
|
|
|
|
|
load()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function searchUniversities() {
|
|
|
|
|
|
page.value = 1
|
|
|
|
|
|
load()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function openCreate() {
|
|
|
|
|
|
editing.value = null
|
|
|
|
|
|
form.value = { name: '', longitude: '', latitude: '', city: '', province: '' }
|
|
|
|
|
|
dialog.value = true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function openEdit(row: UniversityRow) {
|
|
|
|
|
|
editing.value = row
|
|
|
|
|
|
form.value = {
|
|
|
|
|
|
name: row.name,
|
|
|
|
|
|
longitude: row.longitude != null ? String(row.longitude) : '',
|
|
|
|
|
|
latitude: row.latitude != null ? String(row.latitude) : '',
|
|
|
|
|
|
city: row.city || '',
|
|
|
|
|
|
province: row.province || '',
|
|
|
|
|
|
}
|
|
|
|
|
|
dialog.value = true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function save() {
|
|
|
|
|
|
if (!form.value.name || !form.value.longitude || !form.value.latitude) {
|
|
|
|
|
|
ElMessage.warning('请填写高校名称与经纬度')
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
const payload = {
|
|
|
|
|
|
name: form.value.name.trim(),
|
|
|
|
|
|
longitude: Number(form.value.longitude),
|
|
|
|
|
|
latitude: Number(form.value.latitude),
|
|
|
|
|
|
city: form.value.city || null,
|
|
|
|
|
|
province: form.value.province || null,
|
|
|
|
|
|
}
|
|
|
|
|
|
if (editing.value) {
|
|
|
|
|
|
await updateUniversity(editing.value.id, payload)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
await createUniversity(payload)
|
|
|
|
|
|
}
|
|
|
|
|
|
ElMessage.success('已保存')
|
|
|
|
|
|
dialog.value = false
|
|
|
|
|
|
await load()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function remove(row: UniversityRow) {
|
|
|
|
|
|
await ElMessageBox.confirm(`确定要删除高校「${row.name}」?`, '确认删除', { type: 'warning' })
|
|
|
|
|
|
await deleteUniversity(row.id)
|
|
|
|
|
|
ElMessage.success('已删除')
|
|
|
|
|
|
await load()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
usePageLoad(load)
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
|
<div class="list-page">
|
|
|
|
|
|
<div class="page-header">
|
|
|
|
|
|
<h1 class="page-title">高校坐标库</h1>
|
|
|
|
|
|
<el-button type="primary" size="small" class="btn-create" @click="openCreate">新增高校</el-button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<el-card shadow="never" class="admin-list-card">
|
|
|
|
|
|
<p class="list-page-hint">长三角主要高校经纬度预置录入,供雷达地图映射使用。</p>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="list-filter-bar">
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
v-model="keyword"
|
|
|
|
|
|
placeholder="搜索高校名称、经纬度…"
|
|
|
|
|
|
clearable
|
|
|
|
|
|
class="filter-search"
|
|
|
|
|
|
@keyup.enter="searchUniversities"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<el-select v-model="filterRegion" placeholder="地区" clearable class="filter-select-wide">
|
|
|
|
|
|
<el-option v-for="r in regionOptions" :key="r.value" :label="r.label" :value="r.value" />
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
<el-button type="primary" @click="searchUniversities">搜索</el-button>
|
|
|
|
|
|
<el-button @click="resetFilters">重置</el-button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<el-table v-loading="loading" :data="items" row-key="id">
|
|
|
|
|
|
<el-table-column prop="name" label="高校名称" min-width="180" />
|
|
|
|
|
|
<el-table-column label="经度" width="120">
|
|
|
|
|
|
<template #default="{ row }">{{ row.longitude ?? '—' }}</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
<el-table-column label="纬度" width="120">
|
|
|
|
|
|
<template #default="{ row }">{{ row.latitude ?? '—' }}</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
<el-table-column prop="city" label="城市" width="100" />
|
|
|
|
|
|
<el-table-column label="操作" width="160" fixed="right">
|
|
|
|
|
|
<template #default="{ row }">
|
|
|
|
|
|
<div class="table-row-actions">
|
|
|
|
|
|
<el-button class="btn-action-secondary" @click="openEdit(row)">编辑</el-button>
|
|
|
|
|
|
<el-button class="btn-action-secondary" @click="remove(row)">删除</el-button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
</el-table>
|
|
|
|
|
|
|
|
|
|
|
|
<div v-if="meta.total > 0" class="list-pager">
|
|
|
|
|
|
<el-pagination
|
|
|
|
|
|
layout="total, prev, pager, next"
|
|
|
|
|
|
:total="meta.total"
|
|
|
|
|
|
:page-size="meta.per_page"
|
|
|
|
|
|
:current-page="page"
|
|
|
|
|
|
@current-change="(p: number) => { page = p; load() }"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<el-dialog
|
|
|
|
|
|
v-model="dialog"
|
|
|
|
|
|
:title="editing ? '编辑高校' : '新增高校'"
|
|
|
|
|
|
width="480px"
|
|
|
|
|
|
destroy-on-close
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-form label-position="top">
|
|
|
|
|
|
<el-form-item label="高校名称" required>
|
|
|
|
|
|
<el-input v-model="form.name" placeholder="如:复旦大学" />
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-row :gutter="12">
|
|
|
|
|
|
<el-col :span="12">
|
|
|
|
|
|
<el-form-item label="经度" required>
|
|
|
|
|
|
<el-input v-model="form.longitude" placeholder="如:121.5031" />
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
<el-col :span="12">
|
|
|
|
|
|
<el-form-item label="纬度" required>
|
|
|
|
|
|
<el-input v-model="form.latitude" placeholder="如:31.2970" />
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
</el-row>
|
|
|
|
|
|
<el-row :gutter="12">
|
|
|
|
|
|
<el-col :span="12">
|
|
|
|
|
|
<el-form-item label="省份">
|
|
|
|
|
|
<el-input v-model="form.province" placeholder="如:上海" />
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
<el-col :span="12">
|
|
|
|
|
|
<el-form-item label="城市">
|
|
|
|
|
|
<el-input v-model="form.city" placeholder="如:上海" />
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
</el-row>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
<template #footer>
|
|
|
|
|
|
<el-button @click="dialog = false">取消</el-button>
|
|
|
|
|
|
<el-button type="primary" @click="save">保存</el-button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
</template>
|