feat: 完成出差目的地高德地图选择功能(2)
This commit is contained in:
@@ -11,6 +11,7 @@ import com.ruoyi.hrm.domain.bo.HrmTravelReqBo;
|
|||||||
import com.ruoyi.hrm.domain.vo.HrmTravelReqVo;
|
import com.ruoyi.hrm.domain.vo.HrmTravelReqVo;
|
||||||
import com.ruoyi.hrm.service.IHrmTravelReqService;
|
import com.ruoyi.hrm.service.IHrmTravelReqService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@@ -31,6 +32,9 @@ public class HrmTravelReqController extends BaseController {
|
|||||||
private final IHrmTravelReqService service;
|
private final IHrmTravelReqService service;
|
||||||
private final IHrmTravelReqService hrmTravelReqService;
|
private final IHrmTravelReqService hrmTravelReqService;
|
||||||
|
|
||||||
|
@Value("${fad.amap.key}")
|
||||||
|
private String amapKey;
|
||||||
|
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public TableDataInfo<HrmTravelReqVo> list(HrmTravelReqBo bo, PageQuery pageQuery) {
|
public TableDataInfo<HrmTravelReqVo> list(HrmTravelReqBo bo, PageQuery pageQuery) {
|
||||||
return service.queryPageList(bo, pageQuery);
|
return service.queryPageList(bo, pageQuery);
|
||||||
@@ -62,7 +66,10 @@ public class HrmTravelReqController extends BaseController {
|
|||||||
public R<Void> earlyEnd(@PathVariable Long bizId) {
|
public R<Void> earlyEnd(@PathVariable Long bizId) {
|
||||||
return toAjax(hrmTravelReqService.earlyEnd(bizId));
|
return toAjax(hrmTravelReqService.earlyEnd(bizId));
|
||||||
}
|
}
|
||||||
|
@GetMapping("/amapKey")
|
||||||
|
public R<String> getAmapKey() {
|
||||||
|
return R.ok(amapKey);
|
||||||
|
}
|
||||||
@GetMapping("/all")
|
@GetMapping("/all")
|
||||||
public R<List<HrmTravelReqVo>> all(HrmTravelReqBo bo) {
|
public R<List<HrmTravelReqVo>> all(HrmTravelReqBo bo) {
|
||||||
return R.ok(service.queryList(bo));
|
return R.ok(service.queryList(bo));
|
||||||
|
|||||||
@@ -52,3 +52,10 @@ export function earlyEndTravel(bizId) {
|
|||||||
method: 'put'
|
method: 'put'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getAmapKey() {
|
||||||
|
return request({
|
||||||
|
url: '/hrm/travel/amapKey',
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -88,6 +88,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import AMapLoader from '@amap/amap-jsapi-loader'
|
import AMapLoader from '@amap/amap-jsapi-loader'
|
||||||
|
import { getAmapKey } from '@/api/hrm/travel'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'AmapCitySelect',
|
name: 'AmapCitySelect',
|
||||||
@@ -121,6 +122,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
// 弹窗打开时调用
|
||||||
async onDialogOpened() {
|
async onDialogOpened() {
|
||||||
await this.loadAMap()
|
await this.loadAMap()
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
@@ -128,19 +130,25 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 加载高德地图
|
||||||
async loadAMap() {
|
async loadAMap() {
|
||||||
if (this.AMap) return this.AMap
|
if (this.AMap) return this.AMap
|
||||||
|
|
||||||
// 【关键修改:必须在此处配置安全密钥】
|
|
||||||
window._AMapSecurityConfig = {
|
|
||||||
securityJsCode: 'a2969c40309b1a3930f78b2a232d0de0', // 你的安全密钥
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const res = await getAmapKey()
|
||||||
|
console.log("接口完整返回:", JSON.stringify(res))
|
||||||
|
|
||||||
|
const amapkey = res.msg
|
||||||
|
console.log('获取到的Key:', amapkey)
|
||||||
|
|
||||||
|
if (!amapkey) {
|
||||||
|
throw new Error('获取高德地图Key失败')
|
||||||
|
}
|
||||||
|
|
||||||
this.AMap = await AMapLoader.load({
|
this.AMap = await AMapLoader.load({
|
||||||
key: '27baa1cd7dee515accbcf8534d1a2e0e', // 您的Key
|
key: amapkey,
|
||||||
version: '2.0',
|
version: '2.0',
|
||||||
plugins: ['AMap.Geocoder', 'AMap.PlaceSearch'] // 插件在这里被正确加载了
|
plugins: ['AMap.Geocoder', 'AMap.PlaceSearch']
|
||||||
})
|
})
|
||||||
return this.AMap
|
return this.AMap
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user