You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

91 lines
1.9 KiB

import upload from '@/uni_modules/uview-ui/components/u-upload/u-upload'
function getLocationInfo() {
return new Promise((resolve, reject) => {
uni.getLocation({
type: 'gcj02',
geocode: true,
success: (res) => {
resolve(res)
},
fail: (res) => {
reject(err)
}
});
})
}
function string2unicode(str) {
var ret = "";
var ustr = "";
for (var i = 0; i < str.length; i++) {
var code = str.charCodeAt(i);
var code16 = code.toString(16);
if (code < 0xf) {
ustr = "\\u" + "000" + code16;
} else if (code < 0xff) {
ustr = "\\u" + "00" + code16;
} else if (code < 0xfff) {
ustr = "\\u" + "0" + code16;
} else {
ustr = "\\u" + code16;
}
ret += ustr;
//ret += "\\u" + str.charCodeAt(i).toString(16);
}
return ret
}
export default {
functional: true,
render: function(h, context) {
return h(upload, {
...context.data,
on: {
...context.data.on,
afterRead: async (event) => {
try {
// #ifdef APP-PLUS
const locationInfo = await getLocationInfo()
const {
province = '', city = '', district = '', street = '', streetNum = '',
poiName = ''
} = locationInfo.address
const position =
`${province}${city}${district}${street}${streetNum}${poiName}`
console.log(position)
console.log(string2unicode(position))
context.listeners.afterRead({
...event,
longitude: locationInfo.longitude || '',
latitude: locationInfo.latitude || '',
position
})
// #endif
// #ifdef H5
context.listeners.afterRead({
...event,
"longitude": 120.485218,
"latitude": 36.147391,
position: string2unicode('山东省青岛市崂山区新锦路173号青岛国际创新园')
})
// #endif
} catch (e) {
console.log(e, 'event')
context.listeners.afterRead({
...event,
})
//TODO handle the exception
}
}
}
}, context.children)
}
}