查看: 107|回复: 0

fastadmin使用Uniapp开发移动端自定义底部菜单

[复制链接]

748

主题

39

回帖

3907

积分

管理员

总舵主

积分
3907
QQ
发表于 2026-6-24 11:22:49 | 显示全部楼层 |阅读模式
数据表:

  1. CREATE TABLE `fa_eshop_footbar` (
  2.   `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID',
  3.   `weigh` int(11) NOT NULL DEFAULT '0' COMMENT '排序',
  4.   `name` varchar(30) NOT NULL COMMENT '名称',
  5.   `image` varchar(200) NOT NULL COMMENT '图标',
  6.   `act_image` varchar(200) NOT NULL COMMENT '选定图标',
  7.   `color` varchar(30) NOT NULL COMMENT '文字颜色',
  8.   `act_color` varchar(30) NOT NULL COMMENT '选定文字颜色',
  9.   `showtext` enum('1','0') NOT NULL DEFAULT '1' COMMENT '显示文字:1=是,0=否',
  10.   `sizetype` enum('1','2') NOT NULL DEFAULT '1' COMMENT '图标尺寸:1=正常,2=放大',
  11.   `linktype` enum('1','2','3') NOT NULL DEFAULT '1' COMMENT '点击类型:1=跳转页面,2=弹窗,提醒3=跳小程序',
  12.   `pathtype` enum('0','1','2','3','4','5') NOT NULL DEFAULT '0' COMMENT '页面路径:0=首页,1=骑行,2=代理,3=我的,4=其他,5=订单',
  13.   `linkpath` varchar(255) DEFAULT NULL COMMENT '路径地址',
  14.   `icontext` varchar(255) DEFAULT '' COMMENT '非页面路径',
  15.   `status` enum('1','0') NOT NULL DEFAULT '1' COMMENT '状态:1=显示,0=隐藏',
  16.   `createtime` int(16) NOT NULL COMMENT '添加时间',
  17.   `updatetime` int(16) NOT NULL COMMENT '更新时间',
  18.   `deletetime` int(16) DEFAULT NULL COMMENT '删除时间',
  19.   PRIMARY KEY (`id`)
  20. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='底部菜单表';

  21. --
  22. -- 转存表中的数据 `fa_eshop_footbar`
  23. --

  24. INSERT INTO `fa_eshop_footbar` (`id`, `weigh`, `name`, `image`, `act_image`, `color`, `act_color`, `showtext`, `sizetype`, `linktype`, `pathtype`, `linkpath`, `icontext`, `status`, `createtime`, `updatetime`, `deletetime`) VALUES
  25. (1, 3, '设备状态', '/uploads/20260602/7aa4b291de6feed7cb895cb19dfdb391.png', '/uploads/20260602/7aa4b291de6feed7cb895cb19dfdb391.png', '#8a8a8a', '#002fa7', '1', '2', '1', '1', '/pages/travel/index', '', '1', 1778485086, 1781445310, NULL),
  26. (2, 6, '首页', '/uploads/20260617/a62ec65765173fdcc3b859d90404f84f.png', '/uploads/20260617/a54432ee26e163a941def3532a69812c.png', '#8a8a8a', '#ff6600', '1', '1', '1', '0', '/pages/index/index', '', '1', 1778485119, 1782270062, NULL),
  27. (3, 1, '个人中心', '/uploads/20260617/6a1c82080a57d242d0015720a8487ddc.png', '/uploads/20260617/abd0270c07beade4f2308f86c2536445.png', '#8a8a8a', '#ff6600', '1', '1', '1', '3', '/pages/user/index', '', '1', 1778485141, 1782270068, NULL),
  28. (4, 2, '代理入口', '/uploads/20260527/83e887840f19b91d371f5a713079ebb4.png', '/uploads/20260527/83e887840f19b91d371f5a713079ebb4.png', '#8a8a8a', '#ff6600', '1', '1', '1', '2', '/pages/agent/index', '', '0', 1778489782, 1782270374, NULL),
  29. (6, 4, '积分商城', '/uploads/20260617/9f1395e5d7e542eaa24b51c64f71b603.png', '/uploads/20260617/9f1395e5d7e542eaa24b51c64f71b603.png', '#8a8a8a', '#ff6600', '1', '1', '1', '5', '/pages/order/index', '', '0', 1779874724, 1782270369, NULL);
复制代码
前端后台代码:
  1. // 返回值
  2.         $return = [
  3.             'copyright' => $config['copyright'],
  4.             'date' => date('Y-m-d'),
  5.             'footbars' => [],
  6.             'footbar_width' => '',
  7.             'tabIndex' => 0,
  8.             'footbar_switch' => 0,
  9.             'noshowtext' => 0
  10.         ];
  11.         // 底部菜单
  12.         $footbars = Footbar::where('status', 1)->order('weigh', 'desc')->limit(0, 5)->select();
  13.         if (!empty($footbars)) {
  14.             // 数量
  15.             $total = count($footbars);
  16.             if ($total < 2 || $total > 5) {
  17.                 $this->error('底部菜单数量只能2-5个');
  18.             }
  19.             if ($total == 2) {
  20.                 $return['footbar_width'] = '50%';
  21.             } elseif ($total == 3) {
  22.                 $return['footbar_width'] = '33.33%';
  23.             } elseif ($total == 4) {
  24.                 $return['footbar_width'] = '25%';
  25.             } elseif ($total == 5) {
  26.                 $return['footbar_width'] = '20%';
  27.             }
  28.             // 遍历
  29.             foreach ($footbars as $index => &$item) {
  30.                 $item->imageUrl = cdnurl($item->image, true);
  31.                 $item->act_imageUrl = cdnurl($item->act_image, true);
  32.                 if ($item->pathtype == 2) {
  33.                     $return['tabIndex'] = $index;
  34.                     $return['footbar_switch'] = 1;
  35.                 }
  36.                 // 不显示文字
  37.                 if ($item->showtext == 0) {
  38.                     $return['noshowtext'] = 1;
  39.                 }
  40.             }
  41.             unset($item);
  42.             $return['footbars'] = $footbars;
  43.         }
  44.         $this->success('请求成功', $return);
复制代码
uniapp前端代码:
  1. <!-- 底部菜单 -->
  2.                 <view class="nui-footbar" v-if="footbar_switch == 1">
  3.                         <view class="nui-footbar-item" :style="{width: footbar_width}" v-for="(item, index) in footbars" :key="index" @click="tabbar(index)">
  4.                                 <image :src="tabIndex==index?item.act_imageUrl:item.imageUrl" :class="item.sizetype==1?'nui-footbar-image':'nui-footbar-image-large'" mode="widthFix"></image>
  5.                                 <text class="nui-tabname" :style="tabIndex==index?'color:'+item.act_color:item.color" v-if="item.showtext==1">{{item.name}}</text>
  6.                         </view>
  7.                 </view>
复制代码
uniapp前端样式表:
  1. /* 底部菜单 */
  2.         .nui-footbar {
  3.                 position: fixed;
  4.                 bottom: 0;
  5.                 left: 0;
  6.                 right: 0;
  7.                 padding: 10rpx 20rpx;
  8.                 background-color: #ffffff;
  9.                 border-top: 1px solid #ccc;
  10.                 display: flex;
  11.                 /* justify-content: space-between;
  12.                 align-items: center; */
  13.                 flex-direction: row;
  14.                 align-items: flex-end;
  15.                 /* #ifdef MP */
  16.                 padding-top: 16rpx;
  17.                 padding-bottom: 0;
  18.                 /* #endif */
  19.                 z-index: 999;
  20.         }
  21.         .nui-footbar-item {
  22.                 display: flex;
  23.                 flex-direction: column;
  24.                 align-items: center;
  25.                 padding-bottom: env(safe-area-inset-bottom);
  26.         }
  27.         .nui-footbar-image {
  28.                 width: 60rpx;
  29.                 height: auto;
  30.                 display: block;
  31.         }
  32.         .nui-footbar-image-large {
  33.                 width: 100rpx;
  34.                 height: auto;
  35.                 display: block;
  36.         }
  37.         .nui-tabname {
  38.                 font-size: 28rpx;
  39.         }
复制代码
uniapp返回数据代码:
  1. footbar_switch: 0,
  2.                                 footbar_width: '0%',
  3.                                 footbars: [],
  4.                                 tabIndex: 0,
复制代码
uniapp方法:
  1. // 底部菜单
  2.                         tabbar(index) {
  3.                                 // console.log(index)
  4.                                 let footbars = this.footbars;
  5.                                 // console.log(footbars[index])
  6.                                 // 首页
  7.                                 if (index == this.tabIndex) {
  8.                                         return;
  9.                                 } else {
  10.                                         // 跳转页面
  11.                                         if (footbars[index].linktype==1) {
  12.                                                 uni.reLaunch({
  13.                                                         url: footbars[index].linkpath
  14.                                                 })
  15.                                         } else if (footbars[index].linktype==2) {
  16.                                                 // 弹窗提示
  17.                                                 uni.showModal({
  18.                                                         title: '提示',
  19.                                                         content: footbars[index].icontext?footbars[index].icontext:'未配置提示内容',
  20.                                                         showCancel: false
  21.                                                 })
  22.                                         } else {
  23.                                                 // 跳转小程序
  24.                                                 uni.navigateToMiniProgram({
  25.                                                         appId: footbars[index].icontext,
  26.                                                         // envVersion: 'trial',
  27.                                                         // release: 正式版  trial: 体验版
  28.                                                         success: (res) => {
  29.                                                                 console.log('res')
  30.                                                         },
  31.                                                         fail: (res) => {
  32.                                                                 console.log('res')
  33.                                                         }
  34.                                                 })
  35.                                         }
  36.                                 }
  37.                         },
复制代码


道不同,不相为谋!理想要有,万一实现了呢?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注公众号

相关侵权、举报、投诉及建议等,请发 E-mail:2513533699@qq.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.|鲁ICP备19000917号|鲁公网安备37078302000320号

在本版发帖
关注公众号
QQ客服返回顶部