|
|
@@ -683,11 +683,9 @@ request.interceptors.request.use(config => {
|
|
|
style="width: 180px"
|
|
|
clearable
|
|
|
filterable
|
|
|
- remote
|
|
|
- :remote-method="searchShipCompany"
|
|
|
:loading="shipCompanyLoading"
|
|
|
@visible-change="handleShipCompanyVisibleChange"
|
|
|
- @scroll="handleShipCompanyScroll"
|
|
|
+ popper-class="ship-company-select-dropdown"
|
|
|
>
|
|
|
<el-option
|
|
|
v-for="company in shipCompanyList"
|
|
|
@@ -699,7 +697,22 @@ request.interceptors.request.use(config => {
|
|
|
</el-form-item>
|
|
|
```
|
|
|
|
|
|
-#### 11.2.2 数据属性
|
|
|
+#### 11.2.2 样式部分
|
|
|
+
|
|
|
+```css
|
|
|
+/* 船公司下拉框样式 */
|
|
|
+.ship-company-select-dropdown {
|
|
|
+ max-height: 300px;
|
|
|
+ overflow-y: auto;
|
|
|
+}
|
|
|
+
|
|
|
+.ship-company-select-dropdown .el-select-dropdown__wrap {
|
|
|
+ max-height: 300px;
|
|
|
+ overflow-y: auto;
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+#### 11.2.3 数据属性
|
|
|
|
|
|
```javascript
|
|
|
data() {
|
|
|
@@ -708,38 +721,36 @@ data() {
|
|
|
shipownerId: ''
|
|
|
},
|
|
|
shipCompanyList: [],
|
|
|
- shipCompanyQuery: '',
|
|
|
shipCompanyPage: 1,
|
|
|
shipCompanyPageSize: 10,
|
|
|
+ shipCompanyTotal: 0,
|
|
|
shipCompanyLoading: false,
|
|
|
shipCompanyHasMore: true
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
-#### 11.2.3 方法实现
|
|
|
+#### 11.2.4 方法实现
|
|
|
|
|
|
```javascript
|
|
|
methods: {
|
|
|
- getShipCompanyList() {
|
|
|
- this.getShipCompanyListByPage('', 1);
|
|
|
- },
|
|
|
- getShipCompanyListByPage(query, page) {
|
|
|
+ getShipCompanyList(isLoadMore = false) {
|
|
|
this.shipCompanyLoading = true;
|
|
|
this.$axios.get('/api/ship-company/list', {
|
|
|
params: {
|
|
|
- companyName: query,
|
|
|
- page: page,
|
|
|
+ page: this.shipCompanyPage,
|
|
|
pageSize: this.shipCompanyPageSize
|
|
|
}
|
|
|
})
|
|
|
.then(response => {
|
|
|
- if (page === 1) {
|
|
|
- this.shipCompanyList = response.data.content || [];
|
|
|
+ const newCompanies = response.data.content || [];
|
|
|
+ if (isLoadMore) {
|
|
|
+ this.shipCompanyList = [...this.shipCompanyList, ...newCompanies];
|
|
|
} else {
|
|
|
- this.shipCompanyList = [...this.shipCompanyList, ...(response.data.content || [])];
|
|
|
+ this.shipCompanyList = newCompanies;
|
|
|
}
|
|
|
- this.shipCompanyHasMore = response.data.content && response.data.content.length >= this.shipCompanyPageSize;
|
|
|
+ this.shipCompanyTotal = response.data.totalElements || 0;
|
|
|
+ this.shipCompanyHasMore = this.shipCompanyList.length < this.shipCompanyTotal;
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.error('获取船公司列表失败:', error);
|
|
|
@@ -749,26 +760,56 @@ methods: {
|
|
|
this.shipCompanyLoading = false;
|
|
|
});
|
|
|
},
|
|
|
- searchShipCompany(query) {
|
|
|
- this.shipCompanyQuery = query || '';
|
|
|
- this.shipCompanyPage = 1;
|
|
|
- this.getShipCompanyListByPage(this.shipCompanyQuery, this.shipCompanyPage);
|
|
|
- },
|
|
|
handleShipCompanyVisibleChange(visible) {
|
|
|
- if (visible && !this.shipCompanyQuery) {
|
|
|
+ if (visible) {
|
|
|
this.shipCompanyPage = 1;
|
|
|
- this.getShipCompanyListByPage('', this.shipCompanyPage);
|
|
|
+ this.getShipCompanyList();
|
|
|
+ this.addShipCompanyScrollListener();
|
|
|
+ } else {
|
|
|
+ this.removeShipCompanyScrollListener();
|
|
|
}
|
|
|
},
|
|
|
- handleShipCompanyScroll() {
|
|
|
- if (this.shipCompanyHasMore && !this.shipCompanyLoading) {
|
|
|
+ handleShipCompanyScroll(event) {
|
|
|
+ const { target } = event;
|
|
|
+ const scrollBottom = target.scrollHeight - target.scrollTop - target.clientHeight;
|
|
|
+
|
|
|
+ if (scrollBottom < 10 && this.shipCompanyHasMore && !this.shipCompanyLoading) {
|
|
|
this.shipCompanyPage++;
|
|
|
- this.getShipCompanyListByPage(this.shipCompanyQuery, this.shipCompanyPage);
|
|
|
+ this.getShipCompanyList(true);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ addShipCompanyScrollListener() {
|
|
|
+ this.$nextTick(() => {
|
|
|
+ const dropdown = document.querySelector('.ship-company-select-dropdown');
|
|
|
+ if (dropdown) {
|
|
|
+ const dropdownWrap = dropdown.querySelector('.el-select-dropdown__wrap');
|
|
|
+ if (dropdownWrap) {
|
|
|
+ dropdownWrap.addEventListener('scroll', this.handleShipCompanyScroll);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ removeShipCompanyScrollListener() {
|
|
|
+ const dropdown = document.querySelector('.ship-company-select-dropdown');
|
|
|
+ if (dropdown) {
|
|
|
+ const dropdownWrap = dropdown.querySelector('.el-select-dropdown__wrap');
|
|
|
+ if (dropdownWrap) {
|
|
|
+ dropdownWrap.removeEventListener('scroll', this.handleShipCompanyScroll);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
+#### 11.2.5 生命周期钩子
|
|
|
+
|
|
|
+```javascript
|
|
|
+beforeUnmount() {
|
|
|
+ this.removeShipCompanyScrollListener();
|
|
|
+}
|
|
|
+```
|
|
|
+```
|
|
|
+
|
|
|
### 11.3 后端API规范
|
|
|
|
|
|
#### 11.3.1 Controller实现
|