tui-bottom-navigation.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <template>
  2. <view @touchmove.stop.prevent="stop">
  3. <view class="tui-bottom-navigation" :class="{ 'tui-navigation-fixed': isFixed, 'tui-remove-splitLine': unlined }">
  4. <view
  5. class="tui-navigation-item"
  6. :class="{ 'tui-item-after_height': splitLineScale, 'tui-last-item': index == itemList.length - 1 }"
  7. :style="{ backgroundColor: isDarkMode ? '#202020' : backgroundColor }"
  8. v-for="(item, index) in itemList"
  9. :key="index"
  10. >
  11. <view class="tui-item-inner" @tap="menuClick(index, item.parameter, item.type)">
  12. <image
  13. :src="current | getIcon(index, item)"
  14. class="tui-navigation-img"
  15. v-if="item.iconPath || (current == index && item.selectedIconPath && item.type == 1)"
  16. ></image>
  17. <text
  18. class="tui-navigation-text"
  19. :style="{
  20. color: isDarkMode ? '#fff' : current == index && item.type == 1 ? selectedColor : item.color || color,
  21. fontWeight: current == index && bold && item.type == 1 ? 'bold' : 'normal',
  22. fontSize: fontSize
  23. }"
  24. >
  25. {{ item.text }}
  26. </text>
  27. </view>
  28. <view
  29. class="tui-navigation-popup"
  30. :class="{ 'tui-navigation-popup_show': showMenuIndex == index }"
  31. :style="{ backgroundColor: isDarkMode ? '#4c4c4c' : subMenuBgColor, left: item.popupLeft || '50%' }"
  32. v-if="item.itemList"
  33. >
  34. <view
  35. class="tui-popup-cell"
  36. :class="{ 'tui-first-cell': subIndex === 0, 'tui-last-cell': subIndex === item.itemList.length - 1 }"
  37. :hover-class="subMenuHover ? (isDarkMode ? 'tui-item-dark_hover' : 'tui-item-hover') : ''"
  38. :hover-stay-time="150"
  39. v-for="(subItem, subIndex) in item.itemList || []"
  40. :key="subIndex"
  41. @tap="subMenuClick(index, item.type, subIndex, subItem.parameter)"
  42. >
  43. <text class="tui-ellipsis" :style="{ color: isDarkMode ? '#fff' : subMenuColor, fontSize: subMenufontSize, lineHeight: subMenufontSize }">
  44. {{ subItem.text }}
  45. </text>
  46. </view>
  47. <view class="tui-popup-triangle" :style="{ borderTopColor: isDarkMode ? '#4c4c4c' : subMenuBgColor }"></view>
  48. </view>
  49. </view>
  50. </view>
  51. <view class="tui-navigation-mask" :class="{ 'tui-navigation-mask_show': showMenuIndex != -1 }" @tap="handleClose"></view>
  52. </view>
  53. </template>
  54. <script>
  55. export default {
  56. name: 'tuiBottomNavigation',
  57. props: {
  58. //当前索引
  59. current: {
  60. type: Number,
  61. default: 0
  62. },
  63. /**
  64. * {
  65. text: 'ThorUI',
  66. iconPath: '/static/images/common/icon_menu_gray.png',
  67. selectedIconPath: '/static/images/common/icon_menu_gray.png',
  68. color: '#666',
  69. //1-选中切换,2-跳转、请求、其他操作,3-菜单
  70. type: 3,
  71. //自定义参数,类型自定义
  72. parameter: null,
  73. //子菜单left值,不传默认50%,当菜单贴近左右两边可用此参数调整
  74. popupLeft: '',
  75. itemList: [
  76. {
  77. //不建议超过6个字,请自行控制
  78. text: '自定义参',
  79. //自定义参数,类型自定义
  80. parameter: null
  81. },
  82. {
  83. text: '自定义参数',
  84. //自定义参数,类型自定义
  85. parameter: null
  86. }
  87. ]
  88. }
  89. *
  90. * */
  91. itemList: {
  92. type: Array,
  93. default: () => {
  94. return [];
  95. }
  96. },
  97. //颜色
  98. color: {
  99. type: String,
  100. default: '#666'
  101. },
  102. //选中颜色
  103. selectedColor: {
  104. type: String,
  105. default: '#5677fc'
  106. },
  107. fontSize: {
  108. type: String,
  109. default: '28rpx'
  110. },
  111. //选中后字体是否加粗
  112. bold: {
  113. type: Boolean,
  114. default: true
  115. },
  116. //导航条背景颜色
  117. backgroundColor: {
  118. type: String,
  119. default: '#F8F8F8'
  120. },
  121. //item分割线高度是否缩小
  122. splitLineScale: {
  123. type: Boolean,
  124. default: true
  125. },
  126. //二级菜单字体颜色
  127. subMenuColor: {
  128. type: String,
  129. default: '#333'
  130. },
  131. //二级菜单字体大小
  132. subMenufontSize: {
  133. type: String,
  134. default: '28rpx'
  135. },
  136. //二级菜单背景色 深色:#4c4c4c
  137. subMenuBgColor: {
  138. type: String,
  139. default: '#fff'
  140. },
  141. //二级菜单是否有点击效果
  142. subMenuHover: {
  143. type: Boolean,
  144. default: true
  145. },
  146. //是否固定在底部
  147. isFixed: {
  148. type: Boolean,
  149. default: true
  150. },
  151. //去除导航栏顶部的线条
  152. unlined: {
  153. type: Boolean,
  154. default: false
  155. },
  156. //是否暗黑模式 (true:所有设置颜色失效)
  157. isDarkMode: {
  158. type: Boolean,
  159. default: false
  160. }
  161. },
  162. filters: {
  163. getIcon: function(current, index, item) {
  164. let url = item.iconPath;
  165. if (item.type == 1) {
  166. url = current == index ? item.selectedIconPath || item.iconPath : item.iconPath;
  167. }
  168. return url;
  169. }
  170. },
  171. data() {
  172. return {
  173. showMenuIndex: -1 //显示的菜单index
  174. };
  175. },
  176. methods: {
  177. stop() {
  178. return false;
  179. },
  180. handleClose() {
  181. this.showMenuIndex = -1;
  182. },
  183. menuClick(index, parameter, type) {
  184. //type:1-选中切换,2-跳转、请求、其他操作,3-菜单
  185. if (type == 3) {
  186. this.showMenuIndex = this.showMenuIndex == index ? -1 : index;
  187. } else {
  188. this.showMenuIndex = -1;
  189. this.$emit('click', {
  190. menu: 'main', //main,sub 主菜单,子菜单
  191. type: type,
  192. index: index,
  193. parameter: parameter || ''
  194. });
  195. }
  196. },
  197. subMenuClick(index, type, subIndex, parameter) {
  198. this.showMenuIndex = -1;
  199. this.$emit('click', {
  200. menu: 'sub', //main,sub 主菜单,子菜单
  201. type: type,
  202. index: index,
  203. subIndex: subIndex,
  204. parameter: parameter || ''
  205. });
  206. }
  207. }
  208. };
  209. </script>
  210. <style scoped>
  211. .tui-bottom-navigation {
  212. width: 100%;
  213. height: 100rpx;
  214. display: flex;
  215. align-items: center;
  216. justify-content: space-between;
  217. position: relative;
  218. z-index: 999;
  219. }
  220. .tui-navigation-fixed {
  221. position: fixed !important;
  222. left: 0;
  223. bottom: 0;
  224. padding-bottom: env(safe-area-inset-bottom);
  225. }
  226. .tui-bottom-navigation::after {
  227. content: '';
  228. width: 100%;
  229. border-top: 1rpx solid #bfbfbf;
  230. position: absolute;
  231. top: 0;
  232. left: 0;
  233. transform: scaleY(0.5) translateZ(0);
  234. transform-origin: 0 0;
  235. z-index: 1000;
  236. }
  237. .tui-remove-splitLine::before {
  238. border-top: 0 !important;
  239. }
  240. .tui-navigation-item {
  241. flex: 1;
  242. height: 100rpx;
  243. position: relative;
  244. box-sizing: border-box;
  245. }
  246. .tui-item-inner {
  247. width: 100%;
  248. height: 100rpx;
  249. display: flex;
  250. text-align: center;
  251. align-items: center;
  252. justify-content: center;
  253. }
  254. .tui-navigation-item::after {
  255. height: 100%;
  256. content: '';
  257. position: absolute;
  258. border-right: 1rpx solid #bfbfbf;
  259. transform: scaleX(0.5) translateZ(0);
  260. right: 0;
  261. top: 0;
  262. }
  263. .tui-item-after_height::after {
  264. height: 40% !important;
  265. top: 30% !important;
  266. }
  267. .tui-last-item::after {
  268. border-right: 0 !important;
  269. }
  270. .tui-navigation-img {
  271. width: 32rpx;
  272. height: 32rpx;
  273. margin-right: 8rpx;
  274. }
  275. .tui-navigation-popup {
  276. max-width: 160%;
  277. width: auto;
  278. position: absolute;
  279. border-radius: 8rpx;
  280. visibility: hidden;
  281. opacity: 0;
  282. transform: translate3d(-50%, 0, 0);
  283. transform-origin: center;
  284. transition: all 0.12s ease-in-out;
  285. bottom: 0;
  286. z-index: -1;
  287. }
  288. .tui-navigation-popup_show {
  289. transform: translate3d(-50%, -124rpx, 0);
  290. visibility: visible;
  291. opacity: 1;
  292. }
  293. .tui-popup-triangle {
  294. position: absolute;
  295. width: 0;
  296. height: 0;
  297. border-left: 9rpx solid transparent;
  298. border-right: 9rpx solid transparent;
  299. border-top: 18rpx solid;
  300. left: 50%;
  301. bottom: -18rpx;
  302. -webkit-transform: translateX(-50%);
  303. transform: translateX(-50%);
  304. z-index: 997;
  305. }
  306. .tui-popup-cell {
  307. width: 100%;
  308. padding: 32rpx 20rpx;
  309. box-sizing: border-box;
  310. display: flex;
  311. align-items: center;
  312. justify-content: center;
  313. flex: 1;
  314. position: relative;
  315. }
  316. .tui-ellipsis {
  317. white-space: nowrap;
  318. overflow: hidden;
  319. text-overflow: ellipsis;
  320. }
  321. .tui-popup-cell::after {
  322. content: '';
  323. position: absolute;
  324. border-bottom: 1rpx solid #eaeef1;
  325. -webkit-transform: scaleY(0.5);
  326. transform: scaleY(0.5);
  327. bottom: 0;
  328. right: 24rpx;
  329. left: 24rpx;
  330. }
  331. .tui-item-hover {
  332. background-color: #f1f1f1;
  333. }
  334. .tui-item-dark_hover {
  335. background-color: #555;
  336. }
  337. .tui-first-cell {
  338. border-top-left-radius: 8rpx;
  339. border-top-right-radius: 8rpx;
  340. }
  341. .tui-last-cell {
  342. border-bottom-left-radius: 8rpx;
  343. border-bottom-right-radius: 8rpx;
  344. }
  345. .tui-last-cell::after {
  346. border-bottom: 0 !important;
  347. }
  348. .tui-navigation-mask {
  349. position: fixed;
  350. top: 0;
  351. left: 0;
  352. right: 0;
  353. bottom: 0;
  354. z-index: 995;
  355. transition: all 0.3s ease-in-out;
  356. opacity: 0;
  357. visibility: hidden;
  358. background-color: rgba(0, 0, 0, 0);
  359. }
  360. .tui-navigation-mask_show {
  361. opacity: 1;
  362. visibility: visible;
  363. }
  364. </style>