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 { ...@@ -16,11 +16,18 @@ export interface iChatListCard {
isRobootCard?: boolean isRobootCard?: boolean
} }
export interface iOutLet {
id: number
name: string
}
export class MyAppDatabase extends Dexie { export class MyAppDatabase extends Dexie {
chatMessage: Dexie.Table<iChatMessage, number> chatMessage: Dexie.Table<iChatMessage, number>
chatListCard: Dexie.Table<iChatListCard, number> chatListCard: Dexie.Table<iChatListCard, number>
contactPerson: Dexie.Table<iContact2, number> contactPerson: Dexie.Table<iContact2, number>
userInfo: Dexie.Table<iUserinfo, number> userInfo: Dexie.Table<iUserinfo, number>
outlet: Dexie.Table<iOutLet, number>
constructor() { constructor() {
super('MyAppDatabase') super('MyAppDatabase')
...@@ -31,11 +38,13 @@ export class MyAppDatabase extends Dexie { ...@@ -31,11 +38,13 @@ export class MyAppDatabase extends Dexie {
chatListCard: '++id, masterId, targetId, unreadMsgCount, content, inChat, isRobootCard', chatListCard: '++id, masterId, targetId, unreadMsgCount, content, inChat, isRobootCard',
contactPerson: '++id, addr, bank, phone, user_name, out_let_name', contactPerson: '++id, addr, bank, phone, user_name, out_let_name',
userInfo: '++id, created_at, phone, remark, user_name, uuid, addr', userInfo: '++id, created_at, phone, remark, user_name, uuid, addr',
outlet: 'id, name',
}) })
this.chatMessage = this.table('chatMessage') this.chatMessage = this.table('chatMessage')
this.chatListCard = this.table('chatListCard') this.chatListCard = this.table('chatListCard')
this.contactPerson = this.table('contactPerson') this.contactPerson = this.table('contactPerson')
this.userInfo = this.table('userInfo') this.userInfo = this.table('userInfo')
this.outlet = this.table('outlet')
} }
} }
...@@ -41,35 +41,36 @@ class AddressService { ...@@ -41,35 +41,36 @@ class AddressService {
) )
}) })
} }
getGps();
if ('geolocation' in window.navigator) { // if ('geolocation' in window.navigator) {
console.log('geolocation'); // console.log('geolocation');
window.navigator.geolocation.getCurrentPosition( // window.navigator.geolocation.getCurrentPosition(
(position) => { // (position) => {
console.log(position, 'position') // console.log(position, 'position')
const la = position.coords.latitude.toString() // const la = position.coords.latitude.toString()
const lo = position.coords.longitude.toString() // const lo = position.coords.longitude.toString()
resolve( // resolve(
baseAxios<iNearbyOutLet[]>({ // baseAxios<iNearbyOutLet[]>({
method: 'post', // method: 'post',
url: '/address/nearby', // url: '/address/nearby',
data: { // data: {
...data, // ...data,
longitude: lo, // longitude: lo,
latitude: la, // latitude: la,
}, // },
}), // }),
) // )
}, // },
(error) => { // (error) => {
console.log(error) // console.log(error)
getGps() // getGps()
}, // },
) // )
} else { // } else {
console.log('geolocation not in window'); // console.log('geolocation not in window');
getGps() // getGps()
} // }
}) })
} }
......
import { iChatListCard } from '@/db' import { iChatListCard } from '@/db'
import ContactPersonService from '@/db/ContactPersonService' import ContactPersonService from '@/db/ContactPersonService'
import OutletDBService from '@/db/OutletDBService'
import UserInfoDBService from '@/db/UserInfoService' import UserInfoDBService from '@/db/UserInfoService'
import AddressService from '@/service/AddressService' import AddressService from '@/service/AddressService'
import UserService from '@/service/UserService' import UserService from '@/service/UserService'
...@@ -63,16 +64,34 @@ export const getDisplayNamesFromAddress = async ( ...@@ -63,16 +64,34 @@ export const getDisplayNamesFromAddress = async (
/* 获取网点名称 */ /* 获取网点名称 */
export const getDisplayNamesFromOutletId = async (outletids: number[]) => { export const getDisplayNamesFromOutletId = async (outletids: number[]) => {
const promiseList = outletids.map((id) => { const promiseList = outletids.map(async (id) => {
return AddressService.getInstance() 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({ .getOutlet({
id, id,
}) })
.then((ret) => { .then((ret) => {
if (ret.code === 200) { 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) const list = await Promise.all(promiseList)
return list 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