当前位置:   article > 正文

uniapp 微信小程序使用高德地图Vue3不兼容Vue2问题_could not resolve "./amp-wx.130.js

could not resolve "./amp-wx.130.js

1. uniapp 微信小程序使用高德地图Vue3不兼容Vue2问题

1.1. 问题

  uniapp Vue3项目引用高德地图报错
import amapPlugin from ‘…/…/…/js_sdk/js_amap/amap-wx.130’;

"default" is not exported by "../../../MyProject/Base/Szy/js_sdk/js_amap/amap-wx.130.js", imported by "../../../MyProject/Base/Szy/pages/template/pageAmapWx/pageAmapWx.vue".
  • 1

在这里插入图片描述

1.2. 原因

  amap-wx库不支持es6 ES module模块导出,vue3不支持commonjs导入导出

1.3. 处理方案

1.3.1. 下载 微信小程序插件 amap-wx.130.js

下载 微信小程序插件 amap-wx.130.js

1.3.2. 修改 amap-wx.130.js 文件的尾部 module.exports.AMapWX=AMapWX; 修改为 export default { AMapWX };

// module.exports.AMapWX = AMapWX;
export default { AMapWX };
  • 1
  • 2

1.3.3. 修改后完整代码

function AMapWX(a) {
    this.key = a.key;
    this.requestConfig = {
        key: a.key,
        s: "rsx",
        platform: "WXJS",
        appname: a.key,
        sdkversion: "1.2.0",
        logversion: "2.0"
    };
    this.MeRequestConfig = {key: a.key, serviceName: "https://restapi.amap.com/rest/me"}
}

AMapWX.prototype.getWxLocation = function (a, b) {
    wx.getLocation({
        type: "gcj02", success: function (c) {
            c = c.longitude + "," + c.latitude;
            wx.setStorage({key: "userLocation", data: c});
            b(c)
        }, fail: function (c) {
            wx.getStorage({
                key: "userLocation", success: function (d) {
                    d.data && b(d.data)
                }
            });
            a.fail({errCode: "0", errMsg: c.errMsg || ""})
        }
    })
};
AMapWX.prototype.getMEKeywordsSearch = function (a) {
    if (!a.options) return a.fail({errCode: "0", errMsg: "\u7f3a\u5c11\u5fc5\u8981\u53c2\u6570"});
    var b = a.options, c = this.MeRequestConfig,
        d = {key: c.key, s: "rsx", platform: "WXJS", appname: a.key, sdkversion: "1.2.0", logversion: "2.0"};
    b.layerId && (d.layerId = b.layerId);
    b.keywords && (d.keywords = b.keywords);
    b.city && (d.city = b.city);
    b.filter && (d.filter = b.filter);
    b.sortrule && (d.sortrule = b.sortrule);
    b.pageNum && (d.pageNum = b.pageNum);
    b.pageSize && (d.pageSize = b.pageSize);
    b.sig && (d.sig =
        b.sig);
    wx.request({
        url: c.serviceName + "/cpoint/datasearch/local",
        data: d,
        method: "GET",
        header: {"content-type": "application/json"},
        success: function (e) {
            (e = e.data) && e.status && "1" === e.status && 0 === e.code ? a.success(e.data) : a.fail({
                errCode: "0",
                errMsg: e
            })
        },
        fail: function (e) {
            a.fail({errCode: "0", errMsg: e.errMsg || ""})
        }
    })
};
AMapWX.prototype.getMEIdSearch = function (a) {
    if (!a.options) return a.fail({errCode: "0", errMsg: "\u7f3a\u5c11\u5fc5\u8981\u53c2\u6570"});
    var b = a.options, c = this.MeRequestConfig,
        d = {key: c.key, s: "rsx", platform: "WXJS", appname: a.key, sdkversion: "1.2.0", logversion: "2.0"};
    b.layerId && (d.layerId = b.layerId);
    b.id && (d.id = b.id);
    b.sig && (d.sig = b.sig);
    wx.request({
        url: c.serviceName + "/cpoint/datasearch/id",
        data: d,
        method: "GET",
        header: {"content-type": "application/json"},
        success: function (e) {
            (e = e.data) && e.status && "1" === e.status &&
            0 === e.code ? a.success(e.data) : a.fail({errCode: "0", errMsg: e})
        },
        fail: function (e) {
            a.fail({errCode: "0", errMsg: e.errMsg || ""})
        }
    })
};
AMapWX.prototype.getMEPolygonSearch = function (a) {
    if (!a.options) return a.fail({errCode: "0", errMsg: "\u7f3a\u5c11\u5fc5\u8981\u53c2\u6570"});
    var b = a.options, c = this.MeRequestConfig,
        d = {key: c.key, s: "rsx", platform: "WXJS", appname: a.key, sdkversion: "1.2.0", logversion: "2.0"};
    b.layerId && (d.layerId = b.layerId);
    b.keywords && (d.keywords = b.keywords);
    b.polygon && (d.polygon = b.polygon);
    b.filter && (d.filter = b.filter);
    b.sortrule && (d.sortrule = b.sortrule);
    b.pageNum && (d.pageNum = b.pageNum);
    b.pageSize && (d.pageSize = b.pageSize);
    b.sig && (d.sig = b.sig);
    wx.request({
        url: c.serviceName + "/cpoint/datasearch/polygon",
        data: d,
        method: "GET",
        header: {"content-type": "application/json"},
        success: function (e) {
            (e = e.data) && e.status && "1" === e.status && 0 === e.code ? a.success(e.data) : a.fail({
                errCode: "0",
                errMsg: e
            })
        },
        fail: function (e) {
            a.fail({errCode: "0", errMsg: e.errMsg || ""})
        }
    })
};
AMapWX.prototype.getMEaroundSearch = function (a) {
    if (!a.options) return a.fail({errCode: "0", errMsg: "\u7f3a\u5c11\u5fc5\u8981\u53c2\u6570"});
    var b = a.options, c = this.MeRequestConfig,
        d = {key: c.key, s: "rsx", platform: "WXJS", appname: a.key, sdkversion: "1.2.0", logversion: "2.0"};
    b.layerId && (d.layerId = b.layerId);
    b.keywords && (d.keywords = b.keywords);
    b.center && (d.center = b.center);
    b.radius && (d.radius = b.radius);
    b.filter && (d.filter = b.filter);
    b.sortrule && (d.sortrule = b.sortrule);
    b.pageNum && (d.pageNum = b.pageNum);
    b.pageSize &&
    (d.pageSize = b.pageSize);
    b.sig && (d.sig = b.sig);
    wx.request({
        url: c.serviceName + "/cpoint/datasearch/around",
        data: d,
        method: "GET",
        header: {"content-type": "application/json"},
        success: function (e) {
            (e = e.data) && e.status && "1" === e.status && 0 === e.code ? a.success(e.data) : a.fail({
                errCode: "0",
                errMsg: e
            })
        },
        fail: function (e) {
            a.fail({errCode: "0", errMsg: e.errMsg || ""})
        }
    })
};
AMapWX.prototype.getGeo = function (a) {
    var b = this.requestConfig, c = a.options;
    b = {
        key: this.key,
        extensions: "all",
        s: b.s,
        platform: b.platform,
        appname: this.key,
        sdkversion: b.sdkversion,
        logversion: b.logversion
    };
    c.address && (b.address = c.address);
    c.city && (b.city = c.city);
    c.batch && (b.batch = c.batch);
    c.sig && (b.sig = c.sig);
    wx.request({
        url: "https://restapi.amap.com/v3/geocode/geo",
        data: b,
        method: "GET",
        header: {"content-type": "application/json"},
        success: function (d) {
            (d = d.data) && d.status && "1" === d.status ? a.success(d) : a.fail({
                errCode: "0",
                errMsg: d
            })
        },
        fail: function (d) {
            a.fail({errCode: "0", errMsg: d.errMsg || ""})
        }
    })
};
AMapWX.prototype.getRegeo = function (a) {
    function b(d) {
        var e = c.requestConfig;
        wx.request({
            url: "https://restapi.amap.com/v3/geocode/regeo",
            data: {
                key: c.key,
                location: d,
                extensions: "all",
                s: e.s,
                platform: e.platform,
                appname: c.key,
                sdkversion: e.sdkversion,
                logversion: e.logversion
            },
            method: "GET",
            header: {"content-type": "application/json"},
            success: function (g) {
                if (g.data.status && "1" == g.data.status) {
                    g = g.data.regeocode;
                    var h = g.addressComponent, f = [], k = g.roads[0].name + "\u9644\u8fd1", m = d.split(",")[0],
                        n = d.split(",")[1];
                    if (g.pois &&
                        g.pois[0]) {
                        k = g.pois[0].name + "\u9644\u8fd1";
                        var l = g.pois[0].location;
                        l && (m = parseFloat(l.split(",")[0]), n = parseFloat(l.split(",")[1]))
                    }
                    h.provice && f.push(h.provice);
                    h.city && f.push(h.city);
                    h.district && f.push(h.district);
                    h.streetNumber && h.streetNumber.street && h.streetNumber.number ? (f.push(h.streetNumber.street), f.push(h.streetNumber.number)) : f.push(g.roads[0].name);
                    f = f.join("");
                    a.success([{
                        iconPath: a.iconPath,
                        width: a.iconWidth,
                        height: a.iconHeight,
                        name: f,
                        desc: k,
                        longitude: m,
                        latitude: n,
                        id: 0,
                        regeocodeData: g
                    }])
                } else a.fail({
                    errCode: g.data.infocode,
                    errMsg: g.data.info
                })
            },
            fail: function (g) {
                a.fail({errCode: "0", errMsg: g.errMsg || ""})
            }
        })
    }

    var c = this;
    a.location ? b(a.location) : c.getWxLocation(a, function (d) {
        b(d)
    })
};
AMapWX.prototype.getWeather = function (a) {
    function b(g) {
        var h = "base";
        a.type && "forecast" == a.type && (h = "all");
        wx.request({
            url: "https://restapi.amap.com/v3/weather/weatherInfo",
            data: {
                key: d.key,
                city: g,
                extensions: h,
                s: e.s,
                platform: e.platform,
                appname: d.key,
                sdkversion: e.sdkversion,
                logversion: e.logversion
            },
            method: "GET",
            header: {"content-type": "application/json"},
            success: function (f) {
                if (f.data.status && "1" == f.data.status) if (f.data.lives) {
                    if ((f = f.data.lives) && 0 < f.length) {
                        f = f[0];
                        var k = {
                            city: {text: "\u57ce\u5e02", data: f.city},
                            weather: {text: "\u5929\u6c14", data: f.weather},
                            temperature: {text: "\u6e29\u5ea6", data: f.temperature},
                            winddirection: {text: "\u98ce\u5411", data: f.winddirection + "\u98ce"},
                            windpower: {text: "\u98ce\u529b", data: f.windpower + "\u7ea7"},
                            humidity: {text: "\u6e7f\u5ea6", data: f.humidity + "%"}
                        };
                        k.liveData = f;
                        a.success(k)
                    }
                } else f.data.forecasts && f.data.forecasts[0] && a.success({forecast: f.data.forecasts[0]}); else a.fail({
                    errCode: f.data.infocode,
                    errMsg: f.data.info
                })
            },
            fail: function (f) {
                a.fail({errCode: "0", errMsg: f.errMsg || ""})
            }
        })
    }

    function c(g) {
        wx.request({
            url: "https://restapi.amap.com/v3/geocode/regeo",
            data: {
                key: d.key,
                location: g,
                extensions: "all",
                s: e.s,
                platform: e.platform,
                appname: d.key,
                sdkversion: e.sdkversion,
                logversion: e.logversion
            },
            method: "GET",
            header: {"content-type": "application/json"},
            success: function (h) {
                if (h.data.status && "1" == h.data.status) {
                    h = h.data.regeocode;
                    if (h.addressComponent) var f = h.addressComponent.adcode; else h.aois && 0 < h.aois.length && (f = h.aois[0].adcode);
                    b(f)
                } else a.fail({errCode: h.data.infocode, errMsg: h.data.info})
            },
            fail: function (h) {
                a.fail({errCode: "0", errMsg: h.errMsg || ""})
            }
        })
    }

    var d = this, e = d.requestConfig;
    a.city ? b(a.city) : d.getWxLocation(a, function (g) {
        c(g)
    })
};
AMapWX.prototype.getPoiAround = function (a) {
    function b(e) {
        e = {
            key: c.key,
            location: e,
            s: d.s,
            platform: d.platform,
            appname: c.key,
            sdkversion: d.sdkversion,
            logversion: d.logversion
        };
        a.querytypes && (e.types = a.querytypes);
        a.querykeywords && (e.keywords = a.querykeywords);
        wx.request({
            url: "https://restapi.amap.com/v3/place/around",
            data: e,
            method: "GET",
            header: {"content-type": "application/json"},
            success: function (g) {
                if (g.data.status && "1" == g.data.status) {
                    if ((g = g.data) && g.pois) {
                        for (var h = [], f = 0; f < g.pois.length; f++) {
                            var k = 0 ==
                            f ? a.iconPathSelected : a.iconPath;
                            h.push({
                                latitude: parseFloat(g.pois[f].location.split(",")[1]),
                                longitude: parseFloat(g.pois[f].location.split(",")[0]),
                                iconPath: k,
                                width: 22,
                                height: 32,
                                id: f,
                                name: g.pois[f].name,
                                address: g.pois[f].address
                            })
                        }
                        a.success({markers: h, poisData: g.pois})
                    }
                } else a.fail({errCode: g.data.infocode, errMsg: g.data.info})
            },
            fail: function (g) {
                a.fail({errCode: "0", errMsg: g.errMsg || ""})
            }
        })
    }

    var c = this, d = c.requestConfig;
    a.location ? b(a.location) : c.getWxLocation(a, function (e) {
        b(e)
    })
};
AMapWX.prototype.getStaticmap = function (a) {
    function b(e) {
        c.push("location=" + e);
        a.zoom && c.push("zoom=" + a.zoom);
        a.size && c.push("size=" + a.size);
        a.scale && c.push("scale=" + a.scale);
        a.markers && c.push("markers=" + a.markers);
        a.labels && c.push("labels=" + a.labels);
        a.paths && c.push("paths=" + a.paths);
        a.traffic && c.push("traffic=" + a.traffic);
        e = "https://restapi.amap.com/v3/staticmap?" + c.join("&");
        a.success({url: e})
    }

    var c = [];
    c.push("key=" + this.key);
    var d = this.requestConfig;
    c.push("s=" + d.s);
    c.push("platform=" + d.platform);
    c.push("appname=" + d.appname);
    c.push("sdkversion=" + d.sdkversion);
    c.push("logversion=" + d.logversion);
    a.location ? b(a.location) : this.getWxLocation(a, function (e) {
        b(e)
    })
};
AMapWX.prototype.getInputtips = function (a) {
    var b = Object.assign({}, this.requestConfig);
    a.location && (b.location = a.location);
    a.keywords && (b.keywords = a.keywords);
    a.type && (b.type = a.type);
    a.city && (b.city = a.city);
    a.citylimit && (b.citylimit = a.citylimit);
    wx.request({
        url: "https://restapi.amap.com/v3/assistant/inputtips",
        data: b,
        method: "GET",
        header: {"content-type": "application/json"},
        success: function (c) {
            c && c.data && c.data.tips && a.success({tips: c.data.tips})
        },
        fail: function (c) {
            a.fail({
                errCode: "0", errMsg: c.errMsg ||
                    ""
            })
        }
    })
};
AMapWX.prototype.getDrivingRoute = function (a) {
    var b = Object.assign({}, this.requestConfig);
    a.origin && (b.origin = a.origin);
    a.destination && (b.destination = a.destination);
    a.strategy && (b.strategy = a.strategy);
    a.waypoints && (b.waypoints = a.waypoints);
    a.avoidpolygons && (b.avoidpolygons = a.avoidpolygons);
    a.avoidroad && (b.avoidroad = a.avoidroad);
    wx.request({
        url: "https://restapi.amap.com/v3/direction/driving",
        data: b,
        method: "GET",
        header: {"content-type": "application/json"},
        success: function (c) {
            c && c.data && c.data.route && a.success({
                paths: c.data.route.paths,
                taxi_cost: c.data.route.taxi_cost || ""
            })
        },
        fail: function (c) {
            a.fail({errCode: "0", errMsg: c.errMsg || ""})
        }
    })
};
AMapWX.prototype.getWalkingRoute = function (a) {
    var b = Object.assign({}, this.requestConfig);
    a.origin && (b.origin = a.origin);
    a.destination && (b.destination = a.destination);
    wx.request({
        url: "https://restapi.amap.com/v3/direction/walking",
        data: b,
        method: "GET",
        header: {"content-type": "application/json"},
        success: function (c) {
            c && c.data && c.data.route && a.success({paths: c.data.route.paths})
        },
        fail: function (c) {
            a.fail({errCode: "0", errMsg: c.errMsg || ""})
        }
    })
};
AMapWX.prototype.getTransitRoute = function (a) {
    var b = Object.assign({}, this.requestConfig);
    a.origin && (b.origin = a.origin);
    a.destination && (b.destination = a.destination);
    a.strategy && (b.strategy = a.strategy);
    a.city && (b.city = a.city);
    a.cityd && (b.cityd = a.cityd);
    wx.request({
        url: "https://restapi.amap.com/v3/direction/transit/integrated",
        data: b,
        method: "GET",
        header: {"content-type": "application/json"},
        success: function (c) {
            c && c.data && c.data.route && (c = c.data.route, a.success({
                distance: c.distance || "", taxi_cost: c.taxi_cost ||
                    "", transits: c.transits
            }))
        },
        fail: function (c) {
            a.fail({errCode: "0", errMsg: c.errMsg || ""})
        }
    })
};
AMapWX.prototype.getRidingRoute = function (a) {
    var b = Object.assign({}, this.requestConfig);
    a.origin && (b.origin = a.origin);
    a.destination && (b.destination = a.destination);
    wx.request({
        url: "https://restapi.amap.com/v3/direction/riding",
        data: b,
        method: "GET",
        header: {"content-type": "application/json"},
        success: function (c) {
            c && c.data && c.data.route && a.success({paths: c.data.route.paths})
        },
        fail: function (c) {
            a.fail({errCode: "0", errMsg: c.errMsg || ""})
        }
    })
};
// module.exports.AMapWX = AMapWX;
export default { AMapWX };

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • 398
  • 399
  • 400
  • 401
  • 402
  • 403
  • 404
  • 405
  • 406
  • 407
  • 408
  • 409
  • 410
  • 411
  • 412
  • 413
  • 414
  • 415
  • 416
  • 417
  • 418
  • 419
  • 420
  • 421
  • 422
  • 423
  • 424
  • 425
  • 426
  • 427
  • 428
  • 429
  • 430
  • 431
  • 432
  • 433
  • 434
  • 435
  • 436
  • 437
  • 438
  • 439
  • 440
  • 441
  • 442
  • 443
  • 444
  • 445
  • 446
  • 447
  • 448
  • 449
  • 450
  • 451
  • 452
  • 453
  • 454
  • 455
  • 456
  • 457
  • 458
  • 459
  • 460
  • 461
  • 462
  • 463
  • 464
  • 465
  • 466
  • 467
  • 468
  • 469
  • 470
  • 471
  • 472
  • 473
  • 474
  • 475
  • 476
  • 477
  • 478
  • 479
  • 480
  • 481
  • 482
  • 483
  • 484
  • 485
  • 486
  • 487
  • 488
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/203735
推荐阅读
相关标签
  

闽ICP备14008679号