feat(分页组件): 增加分页按钮自定义文本和禁用状态功能
为分页组件添加 prevLabel、nextLabel 和 prevDisabled 属性支持 在首页视图中实现分页导航文本和禁用状态的动态计算 重构分页组件相关代码,移除无用注释并优化代码结构
Showing
2 changed files
with
51 additions
and
15 deletions
| ... | @@ -9,8 +9,8 @@ | ... | @@ -9,8 +9,8 @@ |
| 9 | <div class="pagination-field"> | 9 | <div class="pagination-field"> |
| 10 | <div class="indicator">第{{ current + 1 }}页 / 共{{ total }}页</div> | 10 | <div class="indicator">第{{ current + 1 }}页 / 共{{ total }}页</div> |
| 11 | <div class="actions"> | 11 | <div class="actions"> |
| 12 | - <van-button v-if="showPrev" round type="primary" class="btn" @click="onPrev">上一页</van-button> | 12 | + <van-button v-if="showPrev" :disabled="prevDisabled || current === 0" round type="primary" class="btn" @click="onPrev">{{ prevLabel }}</van-button> |
| 13 | - <van-button v-if="showNext" round type="primary" class="btn" @click="onNext">下一页</van-button> | 13 | + <van-button v-if="showNext" round type="primary" class="btn" @click="onNext">{{ nextLabel }}</van-button> |
| 14 | <van-button v-if="showSubmit" round type="primary" class="btn" @click="onSubmit">提交</van-button> | 14 | <van-button v-if="showSubmit" round type="primary" class="btn" @click="onSubmit">提交</van-button> |
| 15 | </div> | 15 | </div> |
| 16 | </div> | 16 | </div> |
| ... | @@ -21,9 +21,12 @@ | ... | @@ -21,9 +21,12 @@ |
| 21 | import { computed } from 'vue' | 21 | import { computed } from 'vue' |
| 22 | 22 | ||
| 23 | const props = defineProps({ | 23 | const props = defineProps({ |
| 24 | - current: { type: Number, default: 0 }, | 24 | + current: { type: Number, default: 0 }, |
| 25 | - total: { type: Number, default: 1 }, | 25 | + total: { type: Number, default: 1 }, |
| 26 | - isLast: { type: Boolean, default: false }, | 26 | + isLast: { type: Boolean, default: false }, |
| 27 | + prevLabel: { type: String, default: '上一页' }, | ||
| 28 | + nextLabel: { type: String, default: '下一页' }, | ||
| 29 | + prevDisabled: { type: Boolean, default: false }, | ||
| 27 | }) | 30 | }) |
| 28 | 31 | ||
| 29 | const emit = defineEmits(['prev', 'next', 'submit']) | 32 | const emit = defineEmits(['prev', 'next', 'submit']) | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-07-18 10:22:22 | 2 | * @Date: 2022-07-18 10:22:22 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-11-18 18:02:29 | 4 | + * @LastEditTime: 2025-11-18 22:35:35 |
| 5 | * @FilePath: /data-table/src/views/index.vue | 5 | * @FilePath: /data-table/src/views/index.vue |
| 6 | * @Description: 首页 | 6 | * @Description: 首页 |
| 7 | --> | 7 | --> |
| ... | @@ -28,7 +28,18 @@ | ... | @@ -28,7 +28,18 @@ |
| 28 | <component v-for="(item, index) in visible_form_data" :id="item.key" :ref="(el) => setRefMap(el, item)" :key="index" | 28 | <component v-for="(item, index) in visible_form_data" :id="item.key" :ref="(el) => setRefMap(el, item)" :key="index" |
| 29 | :is="item.component" :item="item" @active="onActive" @remove="onRemove" @blur="onBlur" /> | 29 | :is="item.component" :item="item" @active="onActive" @remove="onRemove" @blur="onBlur" /> |
| 30 | </van-cell-group> | 30 | </van-cell-group> |
| 31 | - <pagination-field v-if="enable_pagination" :current="current_page_index" :total="filtered_pages.length" :is-last="current_page_index === filtered_pages.length - 1" @prev="handlePrev" @next="handleNext" @submit="handleSubmit" /> | 31 | + <pagination-field |
| 32 | + v-if="enable_pagination" | ||
| 33 | + :current="current_page_index" | ||
| 34 | + :total="filtered_pages.length" | ||
| 35 | + :is-last="current_page_index === filtered_pages.length - 1" | ||
| 36 | + :prev-label="page_nav.prev_text" | ||
| 37 | + :next-label="page_nav.next_text" | ||
| 38 | + :prev-disabled="page_nav.prev_disabled" | ||
| 39 | + @prev="handlePrev" | ||
| 40 | + @next="handleNext" | ||
| 41 | + @submit="handleSubmit" | ||
| 42 | + /> | ||
| 32 | <!-- 非流程版表单 --> | 43 | <!-- 非流程版表单 --> |
| 33 | <div v-if="formData.length && PCommit.visible && !formSetting.is_flow && !enable_pagination" style="margin: 16px"> | 44 | <div v-if="formData.length && PCommit.visible && !formSetting.is_flow && !enable_pagination" style="margin: 16px"> |
| 34 | <van-button round block type="primary" native-type="submit" :disabled="submitStatus"> | 45 | <van-button round block type="primary" native-type="submit" :disabled="submitStatus"> |
| ... | @@ -240,6 +251,10 @@ const PCommit = ref({}); | ... | @@ -240,6 +251,10 @@ const PCommit = ref({}); |
| 240 | * 表单结构数据 | 251 | * 表单结构数据 |
| 241 | */ | 252 | */ |
| 242 | const formData = ref([]); | 253 | const formData = ref([]); |
| 254 | + | ||
| 255 | +/** | ||
| 256 | + * 分页组件原始数据 | ||
| 257 | + */ | ||
| 243 | const pages_raw = ref([]); | 258 | const pages_raw = ref([]); |
| 244 | // 分页配置 | 259 | // 分页配置 |
| 245 | const enable_pagination = ref(false); | 260 | const enable_pagination = ref(false); |
| ... | @@ -263,6 +278,26 @@ const visible_form_data = computed(() => { | ... | @@ -263,6 +278,26 @@ const visible_form_data = computed(() => { |
| 263 | return formData.value.filter(i => set.has(i.key) && !i.component_props?.disabled); | 278 | return formData.value.filter(i => set.has(i.key) && !i.component_props?.disabled); |
| 264 | }); | 279 | }); |
| 265 | 280 | ||
| 281 | +// 分页组件导航 | ||
| 282 | +const page_nav = computed(() => { | ||
| 283 | + const idx = current_page_index.value; | ||
| 284 | + const keys = filtered_pages.value[idx] || []; | ||
| 285 | + let prev_text = '上一页'; | ||
| 286 | + let next_text = '下一页'; | ||
| 287 | + let prev_disabled = false; | ||
| 288 | + for (let k of keys) { | ||
| 289 | + const item = formData.value.find(i => i.key === k); | ||
| 290 | + if (item && item.component_props) { | ||
| 291 | + // TODO: MOCK 数据 等待真实字段, 分页组件相关属性 | ||
| 292 | + if (item.component_props.page_prev_text) prev_text = item.component_props.page_prev_text; | ||
| 293 | + if (item.component_props.page_next_text) next_text = item.component_props.page_next_text; | ||
| 294 | + if (typeof item.component_props.page_prev_disabled === 'boolean') prev_disabled = item.component_props.page_prev_disabled; | ||
| 295 | + } | ||
| 296 | + } | ||
| 297 | + return { prev_text, next_text, prev_disabled }; | ||
| 298 | +}); | ||
| 299 | +/******* END: 分页组件相关 *******/ | ||
| 300 | + | ||
| 266 | /** | 301 | /** |
| 267 | * 格式化表单数据 | 302 | * 格式化表单数据 |
| 268 | */ | 303 | */ |
| ... | @@ -500,9 +535,7 @@ onMounted(async () => { | ... | @@ -500,9 +535,7 @@ onMounted(async () => { |
| 500 | // }) | 535 | // }) |
| 501 | 536 | ||
| 502 | formData.value = formatData(page_form); | 537 | formData.value = formatData(page_form); |
| 503 | - /** | 538 | + // TAG: 构建分页组件 |
| 504 | - * * TAG: 构建分页组件 | ||
| 505 | - */ | ||
| 506 | buildPages(); | 539 | buildPages(); |
| 507 | enable_pagination.value = filtered_pages.value.length > 1; | 540 | enable_pagination.value = filtered_pages.value.length > 1; |
| 508 | /**** END ****/ | 541 | /**** END ****/ |
| ... | @@ -539,7 +572,7 @@ onMounted(async () => { | ... | @@ -539,7 +572,7 @@ onMounted(async () => { |
| 539 | show_loading.value = false; | 572 | show_loading.value = false; |
| 540 | } | 573 | } |
| 541 | 574 | ||
| 542 | - // TAG:创建组件类型 | 575 | + // TAG: 创建组件类型 |
| 543 | createComponentType(formData.value); | 576 | createComponentType(formData.value); |
| 544 | 577 | ||
| 545 | const isJSON = (value) => { | 578 | const isJSON = (value) => { |
| ... | @@ -551,7 +584,7 @@ onMounted(async () => { | ... | @@ -551,7 +584,7 @@ onMounted(async () => { |
| 551 | } | 584 | } |
| 552 | } | 585 | } |
| 553 | 586 | ||
| 554 | - // TAG:不同类型提交表单处理 | 587 | + // TAG: 不同类型提交表单处理 |
| 555 | if (page_type === 'add' || page_type === undefined) { // 表单为新增状态, 检查是否有未完成的表单信息 | 588 | if (page_type === 'add' || page_type === undefined) { // 表单为新增状态, 检查是否有未完成的表单信息 |
| 556 | const existingCookie = Cookies.get($route.query.code); | 589 | const existingCookie = Cookies.get($route.query.code); |
| 557 | if (existingCookie) { | 590 | if (existingCookie) { |
| ... | @@ -1194,7 +1227,7 @@ const onSubmit = async (values) => { // 表单提交回调 | ... | @@ -1194,7 +1227,7 @@ const onSubmit = async (values) => { // 表单提交回调 |
| 1194 | if (model === 'edit' || model === 'preview' || page_type === 'info') return false; | 1227 | if (model === 'edit' || model === 'preview' || page_type === 'info') return false; |
| 1195 | // 提交按钮禁用 | 1228 | // 提交按钮禁用 |
| 1196 | submitStatus.value = true; | 1229 | submitStatus.value = true; |
| 1197 | - // TAG:不同类型提交表单处理 | 1230 | + // TAG: 不同类型提交表单处理 |
| 1198 | if (page_type === 'add' || page_type == null) { // 新增表单提交 | 1231 | if (page_type === 'add' || page_type == null) { // 新增表单提交 |
| 1199 | let queryObj = { ...$route.query, ...postData.value }; // 大义工传递参数 | 1232 | let queryObj = { ...$route.query, ...postData.value }; // 大义工传递参数 |
| 1200 | // 通过验证 | 1233 | // 通过验证 |
| ... | @@ -1209,7 +1242,7 @@ const onSubmit = async (values) => { // 表单提交回调 | ... | @@ -1209,7 +1242,7 @@ const onSubmit = async (values) => { // 表单提交回调 |
| 1209 | if (result.code) { | 1242 | if (result.code) { |
| 1210 | // 提交按钮禁用状态 | 1243 | // 提交按钮禁用状态 |
| 1211 | submitStatus.value = false; | 1244 | submitStatus.value = false; |
| 1212 | - // | 1245 | + // TAG: 提交成功提示 |
| 1213 | showSuccessToast("提交成功"); | 1246 | showSuccessToast("提交成功"); |
| 1214 | // 缓存表单返回值 | 1247 | // 缓存表单返回值 |
| 1215 | store.changeSuccessInfo(result.data); | 1248 | store.changeSuccessInfo(result.data); |
| ... | @@ -1459,7 +1492,7 @@ const buildPages = () => { | ... | @@ -1459,7 +1492,7 @@ const buildPages = () => { |
| 1459 | formData.value.forEach(item => { | 1492 | formData.value.forEach(item => { |
| 1460 | const tag = item.component_props?.tag; | 1493 | const tag = item.component_props?.tag; |
| 1461 | // TODO: 分页组件标识暂时不确定 | 1494 | // TODO: 分页组件标识暂时不确定 |
| 1462 | - if (tag === 'divider1') { | 1495 | + if (tag === 'divider') { |
| 1463 | if (cur.length) result.push(cur); | 1496 | if (cur.length) result.push(cur); |
| 1464 | cur = []; | 1497 | cur = []; |
| 1465 | return; | 1498 | return; | ... | ... |
-
Please register or login to post a comment