From 6a15551c5a24b67d86a73d5edbd80f4b17a1411e Mon Sep 17 00:00:00 2001 From: Micle Bu Date: Wed, 29 Apr 2020 22:16:02 +0800 Subject: [PATCH] feat(extension): embed: maps (Google Map, AMap, Baidu Map) --- src/components/views/OEmbedView.vue | 3 +- src/data/embed.js | 80 +++++++++++++++++++++++++++++ src/i18n/en-us/index.js | 1 + src/i18n/pl/index.js | 1 + src/i18n/zh-hans/index.js | 5 +- src/statics/service/amap.svg | 1 + 6 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 src/statics/service/amap.svg diff --git a/src/components/views/OEmbedView.vue b/src/components/views/OEmbedView.vue index 99f87fd..9b1b88e 100644 --- a/src/components/views/OEmbedView.vue +++ b/src/components/views/OEmbedView.vue @@ -47,7 +47,8 @@ export default { return } - this.link = this.originalLink + this.originalLink = result.originalLink + this.link = result.originalLink this.src = result.src console.log('result', result) } diff --git a/src/data/embed.js b/src/data/embed.js index 17bd729..e539750 100644 --- a/src/data/embed.js +++ b/src/data/embed.js @@ -17,6 +17,7 @@ export const VideoServices = [ export const MapServices = [ { label: 'Google Map', value: 'google_map', icon: 'mdi-google-maps', color: 'blue' }, + { label: 'AMap', value: 'amap', svgIcon: 'amap' }, { label: 'Baidu Map', value: 'baidu_map', svgIcon: 'baidu-map' }, ] @@ -86,6 +87,25 @@ export const EmbedServiceLink = { src: 'https://v.qq.com/txp/iframe/player.html?vid=i0033cgr1vn', srcPrefix: 'https://v.qq.com/txp/iframe/player.html?vid', linkRule: 'v.qq.com\\/x\\/cover\\/\\w+\\/\\w+', + }, + amap: { + link: 'https://www.amap.com/place/B000A84G4C', + src: 'https://www.amap.com/place/B000A84G4C', + srcPrefix: '', + linkRule: '\\.amap\\.com', + }, + baidu_map: { + link: 'https://map.baidu.com/', + src: 'https://map.baidu.com/', + srcPrefix: '', + linkRule: 'map\\.baidu\\.com', + }, + google_map: { + link: 'https://map.google.com/', + src: 'https://map.google.com/', + srcPrefix: '', + linkRule: 'https:\\/\\/www.google.com\\/maps\\/embed\\?pb=.+sus', + tips: 'Google Map > select location > Share > Embed a map > COPY HTML' } } @@ -185,10 +205,62 @@ function getQQVideoSrc (originalLink, result) { return result } +function getAMapSrc (originalLink, result) { + let link = EmbedServiceLink.amap + let linkRule = link.linkRule + let regex = new RegExp(linkRule) + let match = originalLink.match(regex) + if (match && match.length > 0) { + result.validLink = true + + result.src = originalLink + result.validId = true + } else { + result.validLink = false + } + + return result +} + +function getBaiduMapSrc (originalLink, result) { + let link = EmbedServiceLink.baidu_map + let linkRule = link.linkRule + let regex = new RegExp(linkRule) + let match = originalLink.match(regex) + if (match && match.length > 0) { + result.validLink = true + + result.src = originalLink + result.validId = true + } else { + result.validLink = false + } + + return result +} + +function getGoogleMapSrc (originalLink, result) { + let link = EmbedServiceLink.google_map + let linkRule = link.linkRule + let regex = new RegExp(linkRule) + let match = originalLink.match(regex) + if (match && match.length > 0) { + result.validLink = true + + result.src = match[0] + result.validId = true + } else { + result.validLink = false + } + + return result +} + export const getServiceSrc = (service, originalLink) => { let result = { validLink: false, validId: false, + originalLink: originalLink, src: '' } @@ -201,6 +273,14 @@ export const getServiceSrc = (service, originalLink) => { return getBilibiliSrc(originalLink, result) case 'qqvideo': return getQQVideoSrc(originalLink, result) + case 'amap': + return getAMapSrc(originalLink, result) + case 'baidu_map': + return getBaiduMapSrc(originalLink, result) + case 'google_map': + result = getGoogleMapSrc(originalLink, result) + result.originalLink = result.src + return result } return result diff --git a/src/i18n/en-us/index.js b/src/i18n/en-us/index.js index 6b15604..80182d2 100644 --- a/src/i18n/en-us/index.js +++ b/src/i18n/en-us/index.js @@ -113,6 +113,7 @@ export default { bilibili: 'Bilibili', qqvideo: 'QQ Video', google_map: 'Google Map', + amap: 'AMap', baidu_map: 'Baidu Map', modao: 'Modao', lanhu: 'Lanhu', diff --git a/src/i18n/pl/index.js b/src/i18n/pl/index.js index 6f9faa2..57d5535 100644 --- a/src/i18n/pl/index.js +++ b/src/i18n/pl/index.js @@ -113,6 +113,7 @@ export default { bilibili: 'Bilibili', qqvideo: 'QQ Video', google_map: 'Google Map', + amap: 'AMap', baidu_map: 'Baidu Map', modao: 'Modao', lanhu: 'Lanhu', diff --git a/src/i18n/zh-hans/index.js b/src/i18n/zh-hans/index.js index b0a99f5..8905c54 100644 --- a/src/i18n/zh-hans/index.js +++ b/src/i18n/zh-hans/index.js @@ -112,8 +112,9 @@ export default { iqiyi: '爱奇艺', bilibili: 'Bilibili', qqvideo: '腾讯视频', - google_map: 'Google Map', - baidu_map: 'Baidu Map', + google_map: '谷歌地图', + amap: '高德地图', + baidu_map: '百度', modao: '墨刀', lanhu: '蓝湖', figma: 'Figma', diff --git a/src/statics/service/amap.svg b/src/statics/service/amap.svg new file mode 100644 index 0000000..6834bb2 --- /dev/null +++ b/src/statics/service/amap.svg @@ -0,0 +1 @@ + \ No newline at end of file