more.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <view class="zx-container car-function-set-more">
  3. <view class="fn-wrap">
  4. <view class="title">
  5. {{ $t('固定导航栏') }}
  6. <text class="sort-num">{{ realActiveTabs.length }} / {{ MAX_TAB_LEN }}</text>
  7. </view>
  8. <!-- <draggable v-model="activeTabs" :delay="0" :animation="200" class="tab-item-container">
  9. <view v-for="(tab, index) in activeTabs" :class="['tab-item']" :key="index" @longpress="toggleEdit"
  10. @tap="deleteTab(tab)">
  11. <image v-if="tab.isLock && isActiveEdit" :src="icons.lock" class="right-icon" />
  12. <image v-if="getMovableItem(tab)" :src="icons.edit" class="right-icon" />
  13. <image :src="tab.iconUrl" class="icon" />
  14. <view :class="['name', getMovableItem(tab) && 'shake']">{{ tab.name }}</view>
  15. </view>
  16. </draggable> -->
  17. <basic-drag @end='endFn' @toggleEdit='toggleEdit' v-model="activeTabs" :width="700" :column="4"
  18. itemKey="name"></basic-drag>
  19. </view>
  20. <view class="fn-wrap">
  21. <view class="title">{{ $t('其他功能') }}</view>
  22. <view class="tab-item-container is-to-be-select">
  23. <view v-for="tab in toBeSelectTabs" :key="tab.name" class="tab-item" @longpress="toggleEdit"
  24. @tap="addItemTab(tab)">
  25. <image v-if="showAddIcon" :src="icons.add" class="right-icon" />
  26. <image :src="tab.iconUrl" class="icon" />
  27. <view class="name">{{ $t(tab.name) }}</view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="tips">{{ $t('长按拖动可调整顺序,可增减固定导航栏内容') }}</view>
  32. <view class="un-bind-btn" @tap="toUnbind">{{ $t('解除绑定') }}</view>
  33. </view>
  34. </template>
  35. <script>
  36. // import draggable from 'vuedraggable'
  37. import {
  38. QINIU_URL
  39. } from '@/common/constant'
  40. import BasicDrag from '@/components/basic-drag/index.vue';
  41. import {
  42. setFunctionTag,
  43. getFunctionTag,
  44. } from '@/common/storage.js';
  45. const ICONS = {
  46. lock: `${QINIU_URL}FgMCTZCySvEgLYgkzU65BUR4f4Ls`,
  47. edit: `${QINIU_URL}Fq3V1Zi5tKH7ibTwG1nO7N96CU8m`,
  48. add: `${QINIU_URL}FqLEWbMe8DcnQtNz6GdDDD87ObZK`,
  49. placeholder: `${QINIU_URL}FpKvfFNSDbx0d9RDwyGAQdFb7Kt6`
  50. }
  51. export default {
  52. components: {
  53. // draggable
  54. BasicDrag
  55. },
  56. data() {
  57. const MAX_TAB_LEN = 4
  58. return {
  59. QINIU_URL,
  60. MAX_TAB_LEN,
  61. icons: ICONS,
  62. isActiveEdit: false,
  63. activeTabs: [],
  64. toBeSelectTabs: []
  65. }
  66. },
  67. computed: {
  68. realActiveTabs() {
  69. return this.activeTabs.filter(tab => tab.name)
  70. },
  71. showAddIcon() {
  72. return this.isActiveEdit && this.realActiveTabs.length < this.MAX_TAB_LEN
  73. }
  74. },
  75. created() {
  76. this.initializeTabs()
  77. },
  78. methods: {
  79. endFn(list, removedTab) {
  80. if (removedTab) {
  81. this.toBeSelectTabs.push(removedTab)
  82. this.activeTabs = list
  83. if (this.activeTabs.length < this.MAX_TAB_LEN) {
  84. this.isActiveEdit = true
  85. }
  86. }
  87. this.activeTabsSetFn()
  88. },
  89. getMovableItem(tab) {
  90. return this.isActiveEdit && !tab.isLock && !tab.isPlaceholder
  91. },
  92. initializeTabs() {
  93. const lang = v => this.$t(v)
  94. this.activeTabs = getFunctionTag().activeTag
  95. this.toBeSelectTabs = getFunctionTag().tag
  96. },
  97. toggleEdit(e) {
  98. this.isActiveEdit = e
  99. },
  100. addItemTab(tab) {
  101. const index = this.toBeSelectTabs.findIndex(t => t.name === tab.name)
  102. if (index !== -1) {
  103. const removedTab = this.toBeSelectTabs.splice(index, 1)[0]
  104. this.activeTabs.push(removedTab)
  105. if (this.realActiveTabs.length == this.MAX_TAB_LEN) {
  106. this.isActiveEdit = false
  107. }
  108. }
  109. this.activeTabsSetFn()
  110. },
  111. //处理修改之后的数据
  112. activeTabsSetFn() {
  113. let obj = {
  114. activeTag: this.activeTabs,
  115. tag: this.toBeSelectTabs,
  116. }
  117. setFunctionTag(obj)
  118. },
  119. toUnbind() {
  120. uni.navigateTo({
  121. url: '/pages/carFunctionSet/unbind'
  122. })
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss" scoped>
  128. @import "@/libs/css/layout.scss";
  129. .car-function-set-more {
  130. .fn-wrap {
  131. width: 100%;
  132. background: #FFFFFF;
  133. border-radius: 40rpx;
  134. margin-bottom: 20rpx;
  135. padding: 40rpx 0 48rpx;
  136. .title {
  137. font-family: PingFangSC, PingFang SC;
  138. font-weight: 400;
  139. font-size: 36rpx;
  140. color: #060809;
  141. margin-bottom: 16rpx;
  142. padding-left: 40rpx;
  143. .sort-num {
  144. margin-left: 12rpx;
  145. width: 36rpx;
  146. font-family: Futura, Futura;
  147. font-size: 30rpx;
  148. color: #060809;
  149. }
  150. }
  151. .tab-item-container {
  152. display: flex;
  153. &.is-to-be-select {
  154. flex-wrap: wrap;
  155. }
  156. }
  157. .tab-item {
  158. text-align: center;
  159. width: 25%;
  160. position: relative;
  161. margin-top: 24rpx;
  162. .right-icon {
  163. position: absolute;
  164. right: 20rpx;
  165. top: 0;
  166. width: 40rpx;
  167. height: 40rpx;
  168. z-index: 9;
  169. }
  170. .icon {
  171. width: 112rpx;
  172. height: 112rpx;
  173. margin-bottom: 20rpx;
  174. }
  175. .name {
  176. font-size: 28rpx;
  177. color: #060809;
  178. &.shake {
  179. animation: shake 0.2s ease-in-out infinite;
  180. }
  181. }
  182. }
  183. }
  184. .tips {
  185. font-size: 24rpx;
  186. color: #060809;
  187. text-align: center;
  188. margin-top: 32rpx;
  189. }
  190. .un-bind-btn {
  191. position: absolute;
  192. bottom: 56rpx;
  193. left: 50%;
  194. transform: translateX(-50%);
  195. width: 93%;
  196. padding: 24rpx;
  197. text-align: center;
  198. background: #E4E7EC;
  199. border-radius: 40rpx;
  200. font-family: PingFangSC, PingFang SC;
  201. font-weight: bold;
  202. font-size: 32rpx;
  203. color: #060809;
  204. &:active {
  205. opacity: .7;
  206. }
  207. }
  208. }
  209. </style>