1-获取定位
export const getGeolocation = () => {
return new Promise((resolve) => {
dd.ready(function () {
dd.getGeolocation({
targetAccuracy: 100,
coordinate: 0,
withReGeocode: true,
useCache: false,
})
.then((res) => {
console.log("获取定位信息成功", res);
const { longitude, latitude } = res;
resolve(`X:${longitude} Y:${latitude}`);
})
.catch(() => {
console.log("获取定位信息失败");
resolve("获取定位信息失败");
});
});
});
};
2-代码中添加已经后台配置过的权限编号
export const init= () => {
dd.ready(function () {
dd.getPhoneInfo()
.then(() => {
let corpId="111111";
let zzdAppCode="aaaa";
dd.ready(function () {
dd.getAuthCode({
corpId,
})
.then((info) => {
console.log("code:" + info.code);
axios({
method: "get",
url: `/auth/auth/auu/authCode?authCode=${info.code}&type=token&zzdAppCode=${zzdAppCode}`,
data: {},
contentType: "application/json",
dataType: "json",
})
.then(function (res) {
let RObj = res.data;
if (RObj.success) {
return RObj.data.user_name;
}else{
this.dialog("用户不存在请联系管理员!");
}
})
.catch((err) => {
console.log("获取用户信息失败", err);
});
})
.catch((err) => {
console.log(err);
});
});
})
.catch(() => {
const { username } = window.CONFIG;
return username;
});
});
};
3-鉴权的其他权限配置
getJSApiToken() {
let jsApiList = ["getGeolocation","chooseVideo","uploadLocalFile"];
axios({
headers: {
"X-Gisq-Token": "bearer " + localStorage.getItem("access_token"),
},
method: "get",
url: "/aaa/bbb/ding/getJSApiToken",
contentType: "application/json",
dataType: "json",
}).then(function (res) {
let ticket = res.data.data.accessToken;
dd.ready(() => {
dd.authConfig({
ticket: ticket,
jsApiList: jsApiList,
})
.then((res) => {
console.log('鉴权结果',res);
})
.catch((err) => {
console.log("authConfig错误");
console.log(err);
});
});
});
},