quickConfig.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <view class="uni-app">
  3. <view class="status-bar" />
  4. <view class="main-container">
  5. <wk-nav-bar title="快速入口设置">
  6. <!-- #ifndef MP-WEIXIN -->
  7. <button class="button white-btn" @click="handleSave">
  8. 保存
  9. </button>
  10. <!-- #endif -->
  11. </wk-nav-bar>
  12. <view class="container">
  13. <view class="section">
  14. <view class="section-title">
  15. <text class="section-title__text">
  16. 快速入口
  17. </text>
  18. <text class="section-title__desc">
  19. (长按拖动调整顺序)
  20. </text>
  21. </view>
  22. <view class="wk-drag-sort">
  23. <view
  24. v-for="(item, index) in sortList"
  25. :id="`wk-drag-sort-item-` + index"
  26. :key="item.type"
  27. class="wk-drag-sort-item"
  28. @touchstart="handleTouchstart($event, index)"
  29. @touchmove.stop.prevent="handleTouchmove($event, index)"
  30. @touchend="handleTouchend($event, index)"
  31. @tap.stop="handleRemove(index)">
  32. <view class="quick-item">
  33. <image :src="$static(item.img)" class="img" />
  34. <text class="text">
  35. {{ item.label }}
  36. </text>
  37. <image
  38. :src="$static('images/icon/status_invalid.png')"
  39. class="control-icon" />
  40. </view>
  41. </view>
  42. <template v-if="sortList.length < 4">
  43. <view
  44. v-for="i in (4 - sortList.length)"
  45. :key="i"
  46. class="empty-item" />
  47. </template>
  48. <view
  49. :style="{
  50. left: moveLeft + 'px',
  51. top: moveTop + 'px',
  52. width: itemWidth + 'px',
  53. height: itemHeight + 'px',
  54. visibility: showMoveItem ? 'unset' : 'hidden'
  55. }"
  56. class="move-item">
  57. <view
  58. v-if="moveItemData"
  59. class="quick-item">
  60. <image
  61. :src="$static(moveItemData.img)"
  62. class="img" />
  63. <text
  64. class="text">
  65. {{ moveItemData.label }}
  66. </text>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. <view class="section">
  72. <view class="section-title">
  73. <text class="section-title__text">
  74. 全部
  75. </text>
  76. </view>
  77. <view class="section-body">
  78. <view
  79. v-for="item in otherList"
  80. :key="item.type"
  81. class="quick-item"
  82. @click="handleAdd(item)">
  83. <image :src="$static(item.img)" class="img" />
  84. <text class="text">
  85. {{ item.label }}
  86. </text>
  87. <image
  88. :src="$static('images/icon/add_primary.png')"
  89. class="control-icon" />
  90. </view>
  91. </view>
  92. </view>
  93. </view>
  94. <!-- #ifdef MP-WEIXIN -->
  95. <view class="footer-btn-group">
  96. <button class="button" @click="handleSave">
  97. 保存
  98. </button>
  99. </view>
  100. <!-- #endif -->
  101. </view>
  102. </view>
  103. </template>
  104. <script>
  105. import { GetNavConfig, SetNavConfig } from '@/api/base.js'
  106. import { mapMutations } from 'vuex'
  107. import dragSortMixins from '@/components/wk-drag-sort/mixins.js'
  108. import { quickListLib, getQuickList } from '@/utils/data.js'
  109. import { DEFAULT_NAV_CONFIG } from '@/config.js'
  110. export default {
  111. name: 'HomeQuickConfig',
  112. mixins: [dragSortMixins],
  113. data() {
  114. return {
  115. routerQuery: {},
  116. navConfig: {},
  117. configList: DEFAULT_NAV_CONFIG.quick
  118. }
  119. },
  120. computed: {
  121. otherList() {
  122. return quickListLib.filter(o => !this.configList.includes(o.typeNum))
  123. },
  124. sortList() {
  125. return getQuickList(this.configList)
  126. }
  127. },
  128. onLoad(options) {
  129. this.routerQuery = options
  130. this.initCom()
  131. },
  132. methods: {
  133. ...mapMutations({
  134. setNavFooter: 'user/SET_NAV_FOOTER'
  135. }),
  136. initCom() {
  137. GetNavConfig().then(res => {
  138. this.navConfig = this.$isEmpty(res) ? {} : res[0]
  139. this.configList = this.navConfig.quick || DEFAULT_NAV_CONFIG.quick
  140. if (!this.$isEmpty(this.navConfig)) {
  141. uni.setStorageSync('navConfig', this.navConfig)
  142. }
  143. }).catch(() => {
  144. })
  145. },
  146. handleRemove(index) {
  147. console.log('remove', index)
  148. this.clearMoveItem() // 悬浮结束
  149. this.configList.splice(index, 1)
  150. },
  151. handleSort(list) {
  152. this.configList = list.map(o => o.typeNum)
  153. },
  154. handleAdd(item) {
  155. if (this.configList.length >= 4) {
  156. this.$toast('首页只能添加4个快捷入口')
  157. return
  158. }
  159. this.configList.push(item.typeNum)
  160. },
  161. handleSave() {
  162. if (this.configList.length !== 4) {
  163. this.$toast('首页需要添加4个快捷入口')
  164. return
  165. }
  166. const params = {
  167. ...this.navConfig,
  168. quick: this.configList
  169. }
  170. SetNavConfig([params]).then(() => {
  171. this.setNavFooter(params)
  172. uni.setStorageSync('navConfig', params)
  173. this.$Router.navigateBack()
  174. }).catch(() => {})
  175. }
  176. }
  177. }
  178. </script>
  179. <style scoped lang="scss">
  180. .container {
  181. flex: 1;
  182. .quick-item {
  183. position: relative;
  184. width: calc(25% - 20rpx);
  185. height: 150rpx;
  186. flex-direction: column;
  187. box-shadow: 0px 6rpx 18rpx rgba(232, 232, 233, 0.77);
  188. border-radius: 16rpx;
  189. background-color: white;
  190. margin: 10rpx;
  191. @include center;
  192. .img {
  193. width: 64rpx;
  194. height: 64rpx;
  195. }
  196. .text {
  197. font-size: $wk-font-mini;
  198. margin-top: 10rpx;
  199. }
  200. .control-icon {
  201. position: absolute;
  202. top: 5rpx;
  203. right: 5rpx;
  204. width: 36rpx;
  205. height: 36rpx;
  206. }
  207. }
  208. .empty-item {
  209. width: calc(25% - 20rpx);
  210. height: 150rpx;
  211. box-shadow: unset;
  212. border: 1rpx dashed #999999;
  213. border-radius: 16rpx;
  214. margin: 10rpx;
  215. }
  216. .section {
  217. background-color: white;
  218. padding: 32rpx;
  219. .section-title {
  220. margin-bottom: 20rpx;
  221. .section-title__text {
  222. font-size: $wk-font-large;
  223. font-weight: bold;
  224. color: $dark;
  225. }
  226. .section-title__desc {
  227. font-size: $wk-font-base;
  228. color: $gray;
  229. }
  230. }
  231. .section-body {
  232. width: 100%;
  233. flex-wrap: wrap;
  234. @include left;
  235. }
  236. .wk-drag-sort {
  237. width: 100%;
  238. flex-wrap: wrap;
  239. @include left;
  240. .wk-drag-sort-item {
  241. width: calc(25% - 20rpx);
  242. height: 150rpx;
  243. margin: 10rpx;
  244. }
  245. .quick-item {
  246. width: 100%;
  247. height: 100%;
  248. margin: 0;
  249. }
  250. .move-item {
  251. position: fixed;
  252. visibility: hidden;
  253. z-index: 10;
  254. will-change: top left;
  255. }
  256. }
  257. }
  258. }
  259. </style>