jianghu-ui 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jianghu-ui",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "JianghuJS UI Component Library with Storybook, Vue 2, and Vuetify 2",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -123,8 +123,8 @@
123
123
  </v-list>
124
124
  </div>
125
125
 
126
- <div v-if="level >= 2" class="jh-cascader-column">
127
- <v-list dense class="pa-0" v-if="cities.length">
126
+ <div v-if="level >= 2 && internalValue.province && cities.length" class="jh-cascader-column">
127
+ <v-list dense class="pa-0">
128
128
  <v-list-item v-for="item in cities" :key="item.code" @click="onCityClick(item)" :class="{'v-item--active v-list-item--active primary--text': internalValue.city === item.code}">
129
129
  <v-list-item-content><v-list-item-title :title="item.name">{{ item.name }}</v-list-item-title></v-list-item-content>
130
130
  <v-list-item-action v-if="level > 2"><v-icon small>mdi-chevron-right</v-icon></v-list-item-action>
@@ -132,8 +132,8 @@
132
132
  </v-list>
133
133
  </div>
134
134
 
135
- <div v-if="level >= 3" class="jh-cascader-column">
136
- <v-list dense class="pa-0" v-if="districts.length">
135
+ <div v-if="level >= 3 && internalValue.city && districts.length" class="jh-cascader-column">
136
+ <v-list dense class="pa-0">
137
137
  <v-list-item v-for="item in districts" :key="item.code" @click="onDistrictClick(item)" :class="{'v-item--active v-list-item--active primary--text': internalValue.district === item.code}">
138
138
  <v-list-item-content><v-list-item-title :title="item.name">{{ item.name }}</v-list-item-title></v-list-item-content>
139
139
  <v-list-item-action v-if="level > 3"><v-icon small>mdi-chevron-right</v-icon></v-list-item-action>
@@ -141,8 +141,8 @@
141
141
  </v-list>
142
142
  </div>
143
143
 
144
- <div v-if="level >= 4" class="jh-cascader-column">
145
- <v-list dense class="pa-0" v-if="towns.length">
144
+ <div v-if="level >= 4 && internalValue.district && towns.length" class="jh-cascader-column">
145
+ <v-list dense class="pa-0">
146
146
  <v-list-item v-for="item in towns" :key="item.code" @click="onTownClick(item)" :class="{'v-item--active v-list-item--active primary--text': internalValue.town === item.code}">
147
147
  <v-list-item-content><v-list-item-title :title="item.name">{{ item.name }}</v-list-item-title></v-list-item-content>
148
148
  </v-list-item>
@@ -1442,3 +1442,74 @@ export const SelectionAlertRender = {
1442
1442
  `
1443
1443
  })
1444
1444
  };
1445
+
1446
+ // 受控服务端分页 (完全由父组件控制)
1447
+ export const 受控服务端分页 = {
1448
+ render: () => ({
1449
+ components: { JhTable },
1450
+ data() {
1451
+ return {
1452
+ headers: sampleHeaders,
1453
+ items: [],
1454
+ loading: false,
1455
+ page: 1,
1456
+ itemsPerPage: 10,
1457
+ serverItemsLength: 0,
1458
+ };
1459
+ },
1460
+ mounted() {
1461
+ this.loadData();
1462
+ },
1463
+ watch: {
1464
+ page() {
1465
+ console.log('Page changed to:', this.page);
1466
+ this.loadData();
1467
+ },
1468
+ itemsPerPage() {
1469
+ console.log('Items per page changed to:', this.itemsPerPage);
1470
+ // 通常改变每页大小时建议重置到第一页,但这里取决于业务逻辑
1471
+ // 注意:v-data-table 可能会自动触发 update:page 为 1
1472
+ this.loadData();
1473
+ },
1474
+ },
1475
+ methods: {
1476
+ async loadData() {
1477
+ this.loading = true;
1478
+ console.log(`Loading data: page=${this.page}, size=${this.itemsPerPage}`);
1479
+
1480
+ // 模拟 API 延迟
1481
+ await new Promise(resolve => setTimeout(resolve, 300));
1482
+
1483
+ const total = allMockData.length;
1484
+ const start = (this.page - 1) * this.itemsPerPage;
1485
+ const end = start + this.itemsPerPage;
1486
+
1487
+ this.items = allMockData.slice(start, end);
1488
+ this.serverItemsLength = total;
1489
+ this.loading = false;
1490
+ },
1491
+ },
1492
+ template: `
1493
+ <div>
1494
+ <div class="mb-4 pa-4 orange lighten-5 rounded">
1495
+ <strong>受控服务端分页示例 (无 request 函数)</strong>
1496
+ <p class="mb-0 mt-2">完全由父组件控制 page 和 itemsPerPage,模拟传统的 v-data-table 服务端分页用法。</p>
1497
+ <div class="mt-2">
1498
+ Page: {{ page }} | ItemsPerPage: {{ itemsPerPage }} | Total: {{ serverItemsLength }}
1499
+ </div>
1500
+ </div>
1501
+ <jh-table
1502
+ :headers="headers"
1503
+ :items="items"
1504
+ :loading="loading"
1505
+ :page.sync="page"
1506
+ :items-per-page.sync="itemsPerPage"
1507
+ :server-items-length="serverItemsLength"
1508
+ :footer-props="{
1509
+ 'items-per-page-options': [5, 10, 20]
1510
+ }"
1511
+ />
1512
+ </div>
1513
+ `,
1514
+ }),
1515
+ };
@@ -845,6 +845,19 @@ export default {
845
845
  type: Boolean,
846
846
  default: false
847
847
  },
848
+ // ========== v-data-table 透传 Props (补充) ==========
849
+ page: {
850
+ type: Number,
851
+ default: undefined
852
+ },
853
+ serverItemsLength: {
854
+ type: Number,
855
+ default: undefined
856
+ },
857
+ value: {
858
+ type: Array,
859
+ default: undefined
860
+ },
848
861
  context: {
849
862
  type: Object,
850
863
  default: null
@@ -856,13 +869,13 @@ export default {
856
869
  searchInputInternal: this.searchInput,
857
870
  currentLoading: this.loading,
858
871
  currentItems: this.items || [],
859
- currentPage: this.pagination ? this.pagination.current || 1 : 1,
872
+ currentPage: this.page !== undefined ? this.page : (this.pagination ? this.pagination.current || 1 : 1),
860
873
  currentItemsPerPage: this.itemsPerPage,
861
- serverItemsLength: -1,
874
+ serverItemsLength: this.serverItemsLength !== undefined ? this.serverItemsLength : -1,
862
875
  internalColumns: [],
863
876
  currentDensity: this.size,
864
877
  isFullscreen: false,
865
- selectedItems: [],
878
+ selectedItems: this.value || [],
866
879
  filterValues: {},
867
880
  pollingTimer: null,
868
881
  searchDebounceTimer: null,
@@ -1134,6 +1147,26 @@ export default {
1134
1147
  }
1135
1148
  },
1136
1149
  watch: {
1150
+ page(val) {
1151
+ if (val !== undefined && val !== this.currentPage) {
1152
+ this.currentPage = val;
1153
+ }
1154
+ },
1155
+ serverItemsLength(val) {
1156
+ if (val !== undefined) {
1157
+ this.serverItemsLength = val;
1158
+ }
1159
+ },
1160
+ value(val) {
1161
+ if (val !== undefined) {
1162
+ this.selectedItems = val;
1163
+ }
1164
+ },
1165
+ itemsPerPage(val) {
1166
+ if (val !== undefined && val !== this.currentItemsPerPage) {
1167
+ this.currentItemsPerPage = val;
1168
+ }
1169
+ },
1137
1170
  headers: {
1138
1171
  immediate: true,
1139
1172
  handler(val) {
@@ -1634,6 +1667,7 @@ export default {
1634
1667
  const filters = this.transformFilterValues(queryData);
1635
1668
  this.filterValues = filters;
1636
1669
  this.currentPage = 1; // 重置到第一页
1670
+ this.$emit('update:page', 1);
1637
1671
  this.$emit('filter-search', filters);
1638
1672
  if (this.request) {
1639
1673
  this.reload();
@@ -1643,6 +1677,7 @@ export default {
1643
1677
  handleFilterReset() {
1644
1678
  this.filterValues = {};
1645
1679
  this.currentPage = 1; // 重置到第一页
1680
+ this.$emit('update:page', 1);
1646
1681
  this.$emit('filter-reset');
1647
1682
  if (this.request) {
1648
1683
  this.reload();
@@ -1820,6 +1855,7 @@ export default {
1820
1855
  // 重置到第一页
1821
1856
  reset() {
1822
1857
  this.currentPage = 1;
1858
+ this.$emit('update:page', 1);
1823
1859
  this.reload();
1824
1860
  },
1825
1861
  // 清空选择