This commit is contained in:
Leo
2026-01-05 18:32:29 +08:00
parent 1a4e56bfed
commit a3291f7a31
22 changed files with 3180 additions and 23 deletions

View File

@@ -0,0 +1,174 @@
<template>
<div class="mobile-bottom-nav" v-if="isMobile && show">
<div
v-for="item in navItems"
:key="item.path"
class="nav-item"
:class="{ 'active': isActive(item.path) }"
@click="handleNavClick(item)"
>
<div class="nav-icon">
<i :class="item.icon" v-if="item.icon"></i>
<svg-icon :icon-class="item.iconClass" v-else-if="item.iconClass" />
<el-badge :value="item.badge" :hidden="!item.badge" v-if="item.badge">
<div class="icon-placeholder"></div>
</el-badge>
</div>
<div class="nav-label">{{ item.label }}</div>
</div>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
name: 'MobileBottomNav',
props: {
items: {
type: Array,
default: () => []
},
show: {
type: Boolean,
default: true
}
},
computed: {
...mapGetters(['device']),
isMobile() {
return this.device === 'mobile' || window.innerWidth < 768
},
navItems() {
if (this.items && this.items.length > 0) {
return this.items
}
// 默认导航项 - 从路由中获取
const routes = this.$store?.state?.permission?.routes || []
const mainRoutes = routes.filter(route => route.meta && route.meta.title && !route.hidden)
if (mainRoutes.length > 0) {
return mainRoutes.slice(0, 5).map(route => ({
path: route.path,
label: route.meta.title,
icon: route.meta.icon || 'el-icon-menu',
iconClass: route.meta.icon
}))
}
// 如果没有路由,返回默认导航
return [
{
path: '/index',
label: '首页',
icon: 'el-icon-s-home'
}
]
}
},
methods: {
isActive(path) {
return this.$route.path.startsWith(path)
},
handleNavClick(item) {
if (item.handler) {
item.handler()
} else if (item.path) {
this.$router.push(item.path)
}
this.$emit('nav-click', item)
}
}
}
</script>
<style lang="scss" scoped>
.mobile-bottom-nav {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 60px;
background: #fff;
border-top: 1px solid #e4e7ed;
display: flex;
justify-content: space-around;
align-items: center;
z-index: 1000;
box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
padding-bottom: env(safe-area-inset-bottom);
.nav-item {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 6px 0;
cursor: pointer;
transition: all 0.3s;
-webkit-tap-highlight-color: transparent;
.nav-icon {
width: 28px;
height: 28px;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 4px;
position: relative;
i, .svg-icon {
font-size: 22px;
color: #909399;
transition: all 0.3s;
}
.icon-placeholder {
width: 22px;
height: 22px;
}
}
.nav-label {
font-size: 11px;
color: #909399;
transition: all 0.3s;
}
&.active {
.nav-icon {
i, .svg-icon {
color: #409eff;
font-size: 24px;
}
}
.nav-label {
color: #409eff;
font-weight: 600;
}
}
&:active {
transform: scale(0.95);
opacity: 0.8;
}
}
}
// 桌面端隐藏
@media (min-width: 769px) {
.mobile-bottom-nav {
display: none;
}
}
// 为底部导航预留空间
@media (max-width: 768px) {
.app-main {
padding-bottom: 60px !important;
}
}
</style>

View File

@@ -0,0 +1,188 @@
<template>
<div class="mobile-button-group" :class="{ 'sticky': sticky }">
<!-- 移动端按钮组 -->
<div v-if="isMobile" class="mobile-buttons">
<!-- 主要操作按钮 -->
<div class="primary-actions" v-if="primaryButtons.length > 0">
<el-button
v-for="btn in primaryButtons"
:key="btn.key || btn.label"
:type="btn.type || 'primary'"
:size="btn.size || 'medium'"
:icon="btn.icon"
:disabled="btn.disabled"
:loading="btn.loading"
@click="handleClick(btn)"
class="action-btn"
>
{{ btn.label }}
</el-button>
</div>
<!-- 更多操作下拉菜单 -->
<el-dropdown
v-if="moreButtons.length > 0"
trigger="click"
placement="top-end"
@command="handleCommand"
>
<el-button
type="default"
size="medium"
icon="el-icon-more"
class="more-btn"
>
更多
</el-button>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item
v-for="btn in moreButtons"
:key="btn.key || btn.label"
:command="btn.key || btn.label"
:disabled="btn.disabled"
:divided="btn.divided"
>
<i :class="btn.icon" v-if="btn.icon"></i>
{{ btn.label }}
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
<!-- 桌面端按钮组 -->
<div v-else class="desktop-buttons">
<slot>
<el-button
v-for="btn in allButtons"
:key="btn.key || btn.label"
:type="btn.type || 'default'"
:size="btn.size || 'mini'"
:icon="btn.icon"
:disabled="btn.disabled"
:loading="btn.loading"
:plain="btn.plain"
@click="handleClick(btn)"
>
{{ btn.label }}
</el-button>
</slot>
</div>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
name: 'MobileButtonGroup',
props: {
buttons: {
type: Array,
default: () => []
},
primaryCount: {
type: Number,
default: 2
},
sticky: {
type: Boolean,
default: false
}
},
computed: {
...mapGetters(['device']),
isMobile() {
return this.device === 'mobile' || window.innerWidth < 768
},
allButtons() {
return this.buttons || []
},
primaryButtons() {
return this.allButtons.slice(0, this.primaryCount).filter(btn => !btn.hide)
},
moreButtons() {
return this.allButtons.slice(this.primaryCount).filter(btn => !btn.hide)
}
},
methods: {
handleClick(btn) {
if (btn.handler) {
btn.handler()
}
this.$emit('button-click', btn)
},
handleCommand(command) {
const btn = this.moreButtons.find(b => (b.key || b.label) === command)
if (btn) {
this.handleClick(btn)
}
}
}
}
</script>
<style lang="scss" scoped>
.mobile-button-group {
width: 100%;
&.sticky {
position: sticky;
top: 0;
z-index: 100;
background: #fff;
padding: 12px;
margin: -12px -12px 12px -12px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
}
.mobile-buttons {
display: flex;
gap: 12px;
padding: 12px;
background: #fff;
border-bottom: 1px solid #e4e7ed;
.primary-actions {
flex: 1;
display: flex;
gap: 12px;
.action-btn {
flex: 1;
height: 44px;
font-size: 15px;
border-radius: 8px;
}
}
.more-btn {
flex-shrink: 0;
width: 60px;
height: 44px;
padding: 0;
border-radius: 8px;
}
}
.desktop-buttons {
display: flex;
gap: 10px;
flex-wrap: wrap;
}
// 桌面端隐藏移动端组件
@media (min-width: 769px) {
.mobile-buttons {
display: none;
}
}
// 移动端隐藏桌面端组件
@media (max-width: 768px) {
.desktop-buttons {
display: none;
}
}
</style>

View File

@@ -0,0 +1,259 @@
<template>
<div class="mobile-search-form" :class="{ 'expanded': expanded }">
<!-- 移动端折叠搜索 -->
<div v-if="isMobile" class="mobile-search-wrapper">
<!-- 搜索按钮栏 -->
<div class="search-bar" v-if="!expanded">
<el-input
v-model="quickSearch"
placeholder="快速搜索..."
clearable
@keyup.enter.native="handleQuickSearch"
@clear="handleQuickSearch"
>
<el-button slot="append" icon="el-icon-search" @click="handleQuickSearch"></el-button>
</el-input>
<el-button
type="text"
icon="el-icon-setting"
class="filter-btn"
@click="expanded = true"
>
筛选
</el-button>
</div>
<!-- 展开的搜索表单 -->
<div class="expanded-form" v-if="expanded">
<div class="form-header">
<span class="form-title">筛选条件</span>
<el-button
type="text"
icon="el-icon-close"
@click="expanded = false"
class="close-btn"
></el-button>
</div>
<div class="form-content">
<slot name="form" :expanded="expanded">
<el-form
:model="formData"
label-width="80px"
label-position="top"
>
<slot></slot>
</el-form>
</slot>
</div>
<div class="form-footer">
<el-button @click="handleReset">重置</el-button>
<el-button type="primary" @click="handleSearch">搜索</el-button>
</div>
</div>
</div>
<!-- 桌面端正常显示 -->
<div v-else class="desktop-search-wrapper">
<slot name="form" :expanded="true">
<el-form
:model="formData"
:inline="inline"
:label-width="labelWidth"
>
<slot></slot>
</el-form>
</slot>
</div>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
name: 'MobileSearchForm',
props: {
inline: {
type: Boolean,
default: true
},
labelWidth: {
type: String,
default: '68px'
},
model: {
type: Object,
default: () => ({})
}
},
data() {
return {
expanded: false,
quickSearch: '',
formData: {}
}
},
computed: {
...mapGetters(['device']),
isMobile() {
return this.device === 'mobile' || window.innerWidth < 768
}
},
watch: {
model: {
immediate: true,
deep: true,
handler(val) {
this.formData = { ...val }
}
}
},
methods: {
handleQuickSearch() {
this.$emit('quick-search', this.quickSearch)
},
handleSearch() {
this.$emit('search', this.formData)
this.expanded = false
},
handleReset() {
this.$emit('reset')
this.formData = {}
this.quickSearch = ''
}
}
}
</script>
<style lang="scss" scoped>
.mobile-search-form {
width: 100%;
}
.mobile-search-wrapper {
.search-bar {
display: flex;
gap: 8px;
padding: 12px;
background: #fff;
border-bottom: 1px solid #e4e7ed;
.el-input {
flex: 1;
}
.filter-btn {
flex-shrink: 0;
padding: 0 12px;
font-size: 14px;
min-width: 60px;
}
}
.expanded-form {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: #fff;
z-index: 2000;
display: flex;
flex-direction: column;
animation: slideUp 0.3s ease;
.form-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 16px;
border-bottom: 1px solid #e4e7ed;
background: #fff;
.form-title {
font-size: 16px;
font-weight: 600;
color: #303133;
}
.close-btn {
font-size: 20px;
color: #909399;
}
}
.form-content {
flex: 1;
overflow-y: auto;
padding: 16px;
-webkit-overflow-scrolling: touch;
::v-deep .el-form-item {
margin-bottom: 20px;
.el-form-item__label {
font-size: 14px;
color: #606266;
padding-bottom: 8px;
}
.el-input,
.el-select,
.el-date-picker {
width: 100%;
}
}
}
.form-footer {
display: flex;
gap: 12px;
padding: 16px;
border-top: 1px solid #e4e7ed;
background: #fff;
.el-button {
flex: 1;
height: 44px;
font-size: 16px;
}
}
}
}
.desktop-search-wrapper {
::v-deep .el-form {
.el-form-item {
margin-bottom: 18px;
}
}
}
@keyframes slideUp {
from {
transform: translateY(100%);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
// 桌面端隐藏移动端组件
@media (min-width: 769px) {
.mobile-search-wrapper {
display: none;
}
}
// 移动端隐藏桌面端组件
@media (max-width: 768px) {
.desktop-search-wrapper {
display: none;
}
}
</style>

View File

@@ -0,0 +1,403 @@
<template>
<div class="mobile-table-container">
<!-- 移动端卡片式列表 -->
<div v-if="isMobile" class="mobile-card-list">
<div
v-for="(row, index) in data"
:key="getRowKey(row, index)"
class="mobile-card-item"
:class="{ 'selected': isSelected(row) }"
@click="handleCardClick(row, index)"
>
<!-- 卡片头部 -->
<div class="card-header" v-if="showHeader">
<div class="card-title">
<slot name="header" :row="row" :index="index">
{{ getHeaderText(row) }}
</slot>
</div>
<div class="card-actions" v-if="showSelection || showActions">
<el-checkbox
v-if="showSelection"
:value="isSelected(row)"
@click.stop="handleSelect(row)"
@change="handleSelectChange(row, $event)"
/>
<el-dropdown
v-if="showActions"
trigger="click"
@command="(cmd) => handleAction(cmd, row)"
@click.stop
>
<span class="action-btn" @click.stop>
<i class="el-icon-more"></i>
</span>
<el-dropdown-menu slot="dropdown">
<slot name="actions" :row="row" :index="index">
<el-dropdown-item
v-for="action in actions"
:key="action.key"
:command="action.key"
:disabled="action.disabled && action.disabled(row)"
>
<i :class="action.icon" v-if="action.icon"></i>
{{ action.label }}
</el-dropdown-item>
</slot>
</el-dropdown-menu>
</el-dropdown>
</div>
</div>
<!-- 卡片内容 -->
<div class="card-content">
<slot name="content" :row="row" :index="index">
<div
v-for="column in columns"
:key="column.prop || column.key"
class="card-field"
v-if="column.visible !== false"
>
<div class="field-label">{{ column.label }}</div>
<div class="field-value">
<slot
:name="`column-${column.prop || column.key}`"
:row="row"
:column="column"
:value="getFieldValue(row, column)"
>
<dict-tag
v-if="column.dictType"
:options="getDictOptions(column.dictType)"
:value="getFieldValue(row, column)"
/>
<span v-else-if="column.type === 'switch'">
<el-switch
:value="getFieldValue(row, column)"
:active-value="column.activeValue"
:inactive-value="column.inactiveValue"
@change="(val) => handleSwitchChange(row, column, val)"
disabled
/>
</span>
<span v-else>{{ formatValue(getFieldValue(row, column), column) }}</span>
</slot>
</div>
</div>
</slot>
</div>
<!-- 卡片底部操作 -->
<div class="card-footer" v-if="showFooter">
<slot name="footer" :row="row" :index="index">
<el-button
v-for="btn in footerButtons"
:key="btn.key"
:type="btn.type || 'text'"
:size="btn.size || 'small'"
:icon="btn.icon"
:disabled="btn.disabled && btn.disabled(row)"
@click.stop="handleButtonClick(btn, row)"
>
{{ btn.label }}
</el-button>
</slot>
</div>
</div>
<!-- 空状态 -->
<el-empty
v-if="!data || data.length === 0"
description="暂无数据"
:image-size="100"
/>
</div>
<!-- 桌面端表格 -->
<el-table
v-else
v-bind="$attrs"
:data="data"
v-on="$listeners"
>
<slot></slot>
</el-table>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
name: 'MobileTable',
inheritAttrs: false,
props: {
data: {
type: Array,
default: () => []
},
columns: {
type: Array,
default: () => []
},
rowKey: {
type: [String, Function],
default: 'id'
},
showSelection: {
type: Boolean,
default: false
},
showActions: {
type: Boolean,
default: false
},
showHeader: {
type: Boolean,
default: true
},
showFooter: {
type: Boolean,
default: true
},
actions: {
type: Array,
default: () => []
},
footerButtons: {
type: Array,
default: () => []
},
selectedRows: {
type: Array,
default: () => []
},
headerField: {
type: String,
default: 'name'
}
},
computed: {
...mapGetters(['device']),
isMobile() {
return this.device === 'mobile' || window.innerWidth < 768
}
},
methods: {
getRowKey(row, index) {
if (typeof this.rowKey === 'function') {
return this.rowKey(row, index)
}
return row[this.rowKey] || index
},
isSelected(row) {
if (!this.showSelection || !this.selectedRows) return false
const key = this.getRowKey(row)
return this.selectedRows.some(r => this.getRowKey(r) === key)
},
handleSelect(row) {
this.$emit('select', row)
},
handleSelectChange(row, selected) {
this.$emit('selection-change', row, selected)
},
handleCardClick(row, index) {
this.$emit('row-click', row, index)
},
handleAction(command, row) {
this.$emit('action', command, row)
},
handleButtonClick(btn, row) {
if (btn.handler) {
btn.handler(row)
}
this.$emit('button-click', btn.key, row)
},
getFieldValue(row, column) {
if (column.formatter) {
return column.formatter(row, column, row[column.prop], index)
}
if (typeof column.prop === 'function') {
return column.prop(row)
}
return column.prop ? this.getNestedValue(row, column.prop) : ''
},
getNestedValue(obj, path) {
return path.split('.').reduce((o, p) => o && o[p], obj)
},
formatValue(value, column) {
if (value === null || value === undefined) return '-'
if (column.formatter) {
return column.formatter(null, column, value)
}
return value
},
getHeaderText(row) {
if (this.headerField) {
return this.getNestedValue(row, this.headerField) || '未命名'
}
return row.name || row.title || '未命名'
},
getDictOptions(dictType) {
// 这里需要根据实际的字典获取方式来实现
// 可以通过 this.$store 或 this.$parent 获取字典数据
try {
const dictData = this.$store?.state?.dict?.dict || {}
return dictData[dictType] || []
} catch (e) {
return []
}
},
handleSwitchChange(row, column, value) {
this.$emit('switch-change', row, column, value)
}
}
}
</script>
<style lang="scss" scoped>
.mobile-table-container {
width: 100%;
}
.mobile-card-list {
padding: 10px;
background: #f5f5f5;
min-height: 200px;
}
.mobile-card-item {
background: #fff;
border-radius: 12px;
margin-bottom: 12px;
padding: 16px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
transition: all 0.3s ease;
position: relative;
overflow: hidden;
&:active {
transform: scale(0.98);
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
&.selected {
border: 2px solid #409eff;
background: #f0f9ff;
}
&:last-child {
margin-bottom: 0;
}
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 12px;
padding-bottom: 12px;
border-bottom: 1px solid #f0f0f0;
.card-title {
flex: 1;
font-size: 16px;
font-weight: 600;
color: #303133;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.card-actions {
display: flex;
align-items: center;
gap: 12px;
flex-shrink: 0;
.action-btn {
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
background: #f5f5f5;
color: #606266;
cursor: pointer;
transition: all 0.3s;
&:active {
background: #e4e7ed;
}
i {
font-size: 18px;
}
}
}
}
.card-content {
.card-field {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 12px;
&:last-child {
margin-bottom: 0;
}
.field-label {
font-size: 13px;
color: #909399;
min-width: 80px;
flex-shrink: 0;
margin-right: 12px;
}
.field-value {
flex: 1;
font-size: 14px;
color: #303133;
text-align: right;
word-break: break-all;
::v-deep .el-tag {
margin: 0;
}
}
}
}
.card-footer {
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid #f0f0f0;
display: flex;
gap: 8px;
flex-wrap: wrap;
::v-deep .el-button {
flex: 1;
min-width: 0;
padding: 8px 12px;
}
}
// 桌面端隐藏
@media (min-width: 769px) {
.mobile-card-list {
display: none;
}
}
// 移动端隐藏表格
@media (max-width: 768px) {
::v-deep .el-table {
display: none;
}
}
</style>

View File

@@ -42,7 +42,7 @@ export default {
// 移动端页码按钮的数量端默认值5
pagerCount: {
type: Number,
default: document.body.clientWidth < 992 ? 5 : 7
default: 7
},
layout: {
type: String,
@@ -63,8 +63,19 @@ export default {
},
data() {
return {
isMobile: false
}
},
mounted() {
this.isMobile = window.innerWidth < 768
if (this.isMobile && this.layout === 'total, sizes, prev, pager, next, jumper') {
this.$emit('update:layout', 'prev, pager, next')
}
window.addEventListener('resize', this.handleResize)
},
beforeDestroy() {
window.removeEventListener('resize', this.handleResize)
},
computed: {
currentPage: {
get() {
@@ -84,6 +95,13 @@ export default {
}
},
methods: {
handleResize() {
const wasMobile = this.isMobile
this.isMobile = window.innerWidth < 768
if (wasMobile !== this.isMobile) {
this.$forceUpdate()
}
},
handleSizeChange(val) {
if (this.currentPage * val > this.total) {
this.currentPage = 1
@@ -106,6 +124,33 @@ export default {
<style scoped>
.pagination-container {
background: #fff;
@media (max-width: 768px) {
padding: 10px 0;
::v-deep .el-pagination {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
gap: 5px;
.el-pagination__sizes,
.el-pagination__total,
.el-pagination__jump {
display: none;
}
.btn-prev,
.btn-next,
.el-pager li {
min-width: 36px;
height: 36px;
line-height: 36px;
font-size: 13px;
}
}
}
}
.pagination-container.hidden {
display: none;

View File

@@ -151,4 +151,39 @@ export default {
background-color: #ccc;
margin: 3px auto;
}
// 移动端优化
@media (max-width: 768px) {
.top-right-btn {
float: none;
margin-bottom: 10px;
width: 100%;
display: flex;
justify-content: flex-start;
gap: 8px;
flex-wrap: wrap;
.el-button {
min-width: 44px;
height: 44px;
padding: 0;
&.el-button--mini {
min-width: 40px;
height: 40px;
}
}
}
::v-deep .el-dialog {
width: 95% !important;
margin: 5vh auto !important;
.el-transfer {
display: flex;
flex-direction: column;
gap: 15px;
}
}
}
</style>