blog station

天下事有难易乎?为之,则难者亦易矣;不为,则易者亦难矣。

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
<template>
<div>
<el-select
style="width: 100%; margin-bottom: 10px"
v-model="value"
filterable
remote
reserve-keyword
placeholder="请输入关键词"
:remote-method="handleSearch"
:loading="loading"
@change="selectAddress"
>
<el-option
v-for="item in suggestionList"
:key="item.id"
:label="item.title"
:value="item.id"
>
</el-option>
</el-select>
<div class="map-wrap">
<!-- 地图容器 -->
<div id="mapContainer" style="width: 100%; height: 500px"></div>
<el-button class="confirm-btn" type="primary" circle @click="confirmMap"
>确定</el-button
>
</div>
</div>
</template>

<script>
import axios from "axios";
export default {
data() {
return {
map: null, // 地图实例
search: null, // 搜索实例
suggest: null, // 关键字输入提示实例
markers: null, // 标记点集合
suggestionList: [], // 搜索建议列表
marker: null, // 地图标记点
loading: false,
value: "",
info: null,
};
},
created() {
//解决放大缩小地图控制台一直报错问题
const oldAddEventListener = EventTarget.prototype.addEventListener;
EventTarget.prototype.addEventListener = function (
key,
funcs,
options = {}
) {
oldAddEventListener.call(this, key, funcs, { passive: false });
};
},
mounted() {
this.initMap();
},
methods: {
// 初始化地图
initMap() {
const center = new TMap.LatLng(39.916527, 116.397128); // 默认中心点(北京)
this.map = new TMap.Map("mapContainer", {
center: center,
zoom: 12,
});
this.search = new TMap.service.Search({ pageSize: 10 }); // 新建一个地点搜索类
this.suggest = new TMap.service.Suggestion({
// 新建一个关键字输入提示类
pageSize: 10, // 返回结果每页条目数
region: "", // 限制城市范围
regionFix: false, // 搜索无结果时是否固定在当前城市
});
this.markers = new TMap.MultiMarker({
map: this.map,
geometries: [],
});
// 创建信息窗
this.info = new TMap.InfoWindow({
map: this.map,
position: this.map.getCenter(),
}).close();
this.map.on("click", async (evt) => {
// 清除旧标记
if (this.marker) this.marker.setMap(null);
// 获取click事件返回的poi信息
let poi = evt.poi;
if (poi) {
// 拾取到POI
this.info.setContent(poi.name).setPosition(poi.latLng).open();
const location = new TMap.LatLng(poi.latLng.lat, poi.latLng.lng);
const result = await this.suggest.getSuggestions({
keyword: poi.name,
location,
});
let currentPoi = result.data[0];
let newPoi = {
title: currentPoi.title,
address: currentPoi.address,
id: currentPoi.id,
lat: currentPoi.location.lat,
lng: currentPoi.location.lng,
};
this.selectSite = newPoi;
} else {
// 没有拾取到POI
this.info.close();
}
});
},

// 处理搜索输入(防抖)
handleSearch(query) {
this.loading = true;
this.searchAddress(query);
},
// 调用搜索建议接口
async searchAddress(query) {
if (query !== "") {
this.loading = true;
const result = await this.suggest.getSuggestions({
keyword: query,
});
this.showSuggestions(result.data);
} else {
this.options = [];
}
},

// 显示搜索结果
showSuggestions(list) {
this.loading = false;
this.suggestionList = list.map((item) => ({
title: item.title,
address: item.address,
id: item.id,
lat: item.location.lat,
lng: item.location.lng,
}));
},
// 选中地址
selectAddress(val) {
const item = this.suggestionList.find((item) => item.id === val);
console.log("选中地址:", item);
this.selectSite = item;
const position = new TMap.LatLng(item.lat, item.lng);

// 清除旧标记
if (this.marker) this.marker.setMap(null);
// 添加新标记
this.marker = new TMap.MultiMarker({
map: this.map,
geometries: [{ position }],
});
this.info.setContent(item.title).setPosition(position).open();

// 移动地图中心
this.map.setCenter(position);
},
confirmMap() {
this.$emit("select", this.selectSite);
},
},
};
</script>

<style>
.map-wrap {
position: relative;
}
.confirm-btn {
position: absolute;
bottom: 10px;
right: 10px;
z-index: 1001;
padding: 20px 10px !important;
font-size: 24px;
}
</style>

官网:https://nuxt.com.cn/

配置环境变量

1.根目录下新建文件.env.development.env.production,当然文件.env.xxx都行,只要和后面对应上即可;
2.文件中增加全局环境变量,例如:PUBLIC_API_BASE=https://api.com;
3.nuxt.config.ts配置文件增加配置项:

1
2
3
4
5
6
7
8
export default defineNuxtConfig({
runtimeConfig: {
apiKey: '',//默认为空字符串,在运行时使用process.env.NUXT_API_KEY自动设置,为项目域名
public: {
baseURL: process.env.PUBLIC_API_BASE //暴露在前端的自定义路径
}
},
})
阅读全文 »

新建项目

项目配置

1.开启 PreBundle 配置

开发环境热更新占用内存可以大大降低,热更新所需时间也将大幅减少;生产模式也可以通过提前编译依赖,大幅提升部署效率。

阅读全文 »

条件编译快捷命令

选中要条件编译的代码块,ctrl + alt + /即可生成正确注释

1
2
3
// #ifdef APP
uni.hideNavigationBarLoading();
// #endif

滚动一屏,sticky失效

阅读全文 »

之前一直懒没有安装nvm,现在安装上发现又简单又方便,真香!

注意:在下载nvm之前需要卸载本电脑已经安装的node!

一、进入官网http://nvm.uihtm.com/ 或者githubhttps://github.com/coreybutler/nvm-windows/releases 下载:

阅读全文 »

如果说flex布局是一维布局,则grid布局则是二维布局

1
2
3
4
5
6
7
8
9
阅读全文 »

css优化

  1. 加载性能:
    (1)css压缩:将写好的css进行打包压缩,可以减少很多的体积。
    (2)css单一样式:当需要下边距和左边距的时候,很多时候选择:margin:top0 bottom:0;margin-bottom:bottom;margin-left:left;执行的效率更高。
    (3)减少使用@import,而建议使用link,因为后者在页面加载时一起加载,前者是等待页面加载完成之后再进行加载。

    阅读全文 »

方法

如果table分页最后一页只有一条数据,删除这条会导致分页和数据展示不一致

原因:如果需求要求记录当前table页,删除之后没有判断当前页是否还有数据,所以判断如果当前页只有一条&&当前页大于1,则重新请求时页数-1

1
2
3
4
5
6
7
8
9
10
11
12
13
onDeleteItem: id => {
dispatch({
type: 'nodeManage/delete',
payload: { id },
}).then(() => {
this.handleRefresh({
page:
list.length === 1 && pagination.current > 1
? pagination.current - 1
: pagination.current,
})
})
}
阅读全文 »
0%