输入代码查询 以及 优化 数据库储存

This commit is contained in:
TimSpan 2024-09-03 10:42:45 +08:00
parent 8ce9714a0a
commit ad682a2f78
1 changed files with 44 additions and 28 deletions

View File

@ -22,7 +22,7 @@
v-model:value="value" v-model:value="value"
:options="options" :options="options"
:show-search="{ filter }" :show-search="{ filter }"
placeholder="请输入搜索关键词" placeholder="请选择行政区划"
/> />
</a-form-item> </a-form-item>
<a-form-item v-else label="行政区划"> <a-form-item v-else label="行政区划">
@ -64,6 +64,7 @@
<div>账户{{ account }}</div> <div>账户{{ account }}</div>
<div>密码{{ password }}</div> <div>密码{{ password }}</div>
</a-card> </a-card>
<a-input v-if="isHasAccount" class="w-40 mb-8" v-model:value="searchCode.code" autocomplete="off" placeholder="请输入单位代码查询" />
<a-button v-if="isHasAccount" size="large" type="primary" :loading="loading" @click="getCheckStatus"> 查询审核状态 </a-button> <a-button v-if="isHasAccount" size="large" type="primary" :loading="loading" @click="getCheckStatus"> 查询审核状态 </a-button>
<a-button v-if="isLogin" size="large" type="primary" @click="toLogin"> 去登录 </a-button> <a-button v-if="isLogin" size="large" type="primary" @click="toLogin"> 去登录 </a-button>
</div> </div>
@ -142,40 +143,44 @@ const storeTreeData = async (data: any) => {
// IndexedDB // IndexedDB
const loadTreeFromCache = async (): Promise<any | null> => { const loadTreeFromCache = async (): Promise<any | null> => {
const db = await openDB() // const db = await openDB()
const transaction = db.transaction(storeName, 'readonly') // const transaction = db.transaction(storeName, 'readonly')
const store = transaction.objectStore(storeName) // const store = transaction.objectStore(storeName)
// 'treeData' return new Promise<any | null>((resolve, reject) => {
const request = store.get('treeData') const request = store.get('treeData')
// request.onsuccess = () => {
request.onsuccess = () => { // console.log('🚀 ~ loadTreeFromCache ~ request.result:', request.result)
if (request.result) { if (request.result !== undefined) {
// resolve(request.result) //
options.value = request.result // options.value } else {
resolve(null) // null
}
} }
}
request.onerror = () => {
reject(request.error)
}
})
} }
// IndexedDB // IndexedDB
const getTree = async () => { const getTree = async () => {
// //
const cachedData = await loadTreeFromCache() const cachedData = await loadTreeFromCache()
// console.log('🚀 ~ getTree ~ cachedData:', cachedData)
if (cachedData) { if (cachedData) {
console.log('未发请求')
// 使 // 使
options.value = cachedData options.value = cachedData
console.log('Loaded from cache:', cachedData) // console.log('Loaded from cache:', cachedData)
} else { } else {
console.log('发起了请求')
// API // API
const res = await api.get<any>('/common/administrativeDivisionTree') const res = await api.get<any>('/common/administrativeDivisionTree')
console.log(res)
options.value = res.data options.value = res.data
// IndexedDB
await storeTreeData(res.data) await storeTreeData(res.data)
console.log('Loaded from API and stored in cache')
} }
} }
import type { Rule } from 'ant-design-vue/es/form' import type { Rule } from 'ant-design-vue/es/form'
@ -217,7 +222,7 @@ const checkIsNull = async (_rule: Rule, value: string) => {
} }
} }
const checkOBJ = async (_rule: Rule, value: ContactPersonInfo) => { const checkOBJ = async (_rule: Rule, value: ContactPersonInfo) => {
console.log('🚀 ~ checkOBJ ~ value:', value) // console.log('🚀 ~ checkOBJ ~ value:', value)
if (value.telephone !== '' && value.name !== '') { if (value.telephone !== '' && value.name !== '') {
return Promise.resolve() return Promise.resolve()
@ -262,6 +267,7 @@ const handleFinishFailed = (errors: any) => {
} }
const resetForm = () => { const resetForm = () => {
formRef.value.resetFields() formRef.value.resetFields()
value.value = []
} }
const handleValidate = (...args: any[]) => { const handleValidate = (...args: any[]) => {
console.log(args) console.log(args)
@ -273,19 +279,29 @@ const account = ref<string>('')
const password = ref<string>('') const password = ref<string>('')
const isHasAccount = ref<boolean>(true) const isHasAccount = ref<boolean>(true)
const isLogin = ref<boolean>(false) const isLogin = ref<boolean>(false)
// const searchCode = ref<string>()
//
const searchCode = reactive({
code: __APP_ENV.VITE_APP_ENV === 'development' ? 'dawda' : '',
})
const getCheckStatus = () => { const getCheckStatus = () => {
loading.value = true loading.value = true
api.post<any>('/management/getCheckStatus', { onlyCode: 'dawda', unitOptType: 'POLICE_UNIT' }).then((res) => { api
console.log('🚀 ~ api.post<any> ~ res:', res) .post<any>('/management/getCheckStatus', { onlyCode: searchCode.code, unitOptType: 'POLICE_UNIT' })
if (res.code === 200) { .then((res) => {
console.log('🚀 ~ api.post<any> ~ res:', res)
if (res.code === 200) {
loading.value = false
isHasAccount.value = false
isLogin.value = true
account.value = res.data.account
password.value = res.data.password
}
})
.finally(() => {
loading.value = false loading.value = false
isHasAccount.value = false })
isLogin.value = true
account.value = res.data.account
password.value = res.data.password
}
})
} }
const toLogin = () => { const toLogin = () => {
router.replace({ path: '/login' }) router.replace({ path: '/login' })