Commit 3dddb664 authored by chenqikuai's avatar chenqikuai

fix

parent 7996255f
import { iOutLet, MyAppDatabase } from '.'
export default class OutletDBService {
static instance: OutletDBService
outlet: Dexie.Table<iOutLet, number>
static getInstance() {
if (!OutletDBService.instance)
OutletDBService.instance = new OutletDBService()
return OutletDBService.instance
}
constructor() {
const db = new MyAppDatabase()
this.outlet = db.outlet
}
add(outlet: iOutLet) {
return this.outlet.add(outlet)
}
update(outlet: iOutLet) {
return this.outlet.update(outlet.id, outlet)
}
delete(id: number) {
return this.outlet.delete(id)
}
get(id: number) {
return this.outlet.get(id)
}
}
......@@ -16,11 +16,18 @@ export interface iChatListCard {
isRobootCard?: boolean
}
export interface iOutLet {
id: number
name: string
}
export class MyAppDatabase extends Dexie {
chatMessage: Dexie.Table<iChatMessage, number>
chatListCard: Dexie.Table<iChatListCard, number>
contactPerson: Dexie.Table<iContact2, number>
userInfo: Dexie.Table<iUserinfo, number>
outlet: Dexie.Table<iOutLet, number>
constructor() {
super('MyAppDatabase')
......@@ -31,11 +38,13 @@ export class MyAppDatabase extends Dexie {
chatListCard: '++id, masterId, targetId, unreadMsgCount, content, inChat, isRobootCard',
contactPerson: '++id, addr, bank, phone, user_name, out_let_name',
userInfo: '++id, created_at, phone, remark, user_name, uuid, addr',
outlet: 'id, name',
})
this.chatMessage = this.table('chatMessage')
this.chatListCard = this.table('chatListCard')
this.contactPerson = this.table('contactPerson')
this.userInfo = this.table('userInfo')
this.outlet = this.table('outlet')
}
}
......@@ -41,35 +41,36 @@ class AddressService {
)
})
}
getGps();
if ('geolocation' in window.navigator) {
console.log('geolocation');
window.navigator.geolocation.getCurrentPosition(
(position) => {
console.log(position, 'position')
const la = position.coords.latitude.toString()
const lo = position.coords.longitude.toString()
resolve(
baseAxios<iNearbyOutLet[]>({
method: 'post',
url: '/address/nearby',
data: {
...data,
longitude: lo,
latitude: la,
},
}),
)
},
(error) => {
console.log(error)
getGps()
},
)
} else {
console.log('geolocation not in window');
getGps()
}
// if ('geolocation' in window.navigator) {
// console.log('geolocation');
// window.navigator.geolocation.getCurrentPosition(
// (position) => {
// console.log(position, 'position')
// const la = position.coords.latitude.toString()
// const lo = position.coords.longitude.toString()
// resolve(
// baseAxios<iNearbyOutLet[]>({
// method: 'post',
// url: '/address/nearby',
// data: {
// ...data,
// longitude: lo,
// latitude: la,
// },
// }),
// )
// },
// (error) => {
// console.log(error)
// getGps()
// },
// )
// } else {
// console.log('geolocation not in window');
// getGps()
// }
})
}
......
import { iChatListCard } from '@/db'
import ContactPersonService from '@/db/ContactPersonService'
import OutletDBService from '@/db/OutletDBService'
import UserInfoDBService from '@/db/UserInfoService'
import AddressService from '@/service/AddressService'
import UserService from '@/service/UserService'
......@@ -63,16 +64,34 @@ export const getDisplayNamesFromAddress = async (
/* 获取网点名称 */
export const getDisplayNamesFromOutletId = async (outletids: number[]) => {
const promiseList = outletids.map((id) => {
return AddressService.getInstance()
const promiseList = outletids.map(async (id) => {
const outlet = await OutletDBService.getInstance().get(id)
if (!outlet) {
const ret = await AddressService.getInstance().getOutlet({
id,
})
if (ret.code === 200) {
await OutletDBService.getInstance().add({
name: ret.data.outlet_name,
id: ret.data.id,
})
return ret.data.outlet_name
}
} else {
AddressService.getInstance()
.getOutlet({
id,
})
.then((ret) => {
if (ret.code === 200) {
return ret.data.outlet_name
OutletDBService.getInstance().update({
name: ret.data.outlet_name,
id: ret.data.id,
})
}
})
return outlet.name
}
})
const list = await Promise.all(promiseList)
return list
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment