commonConfig.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. <scroll-view scroll-y 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.icon)" 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 < 8">
  43. <view
  44. v-for="i in (8 - 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.icon)"
  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 crmList"
  80. :key="item.type"
  81. class="quick-item"
  82. @click="handleAdd(item)">
  83. <image :src="$static(item.icon)" 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 class="section">
  94. <view class="section-title">
  95. <text class="section-title__text">
  96. 办公
  97. </text>
  98. </view>
  99. <view class="section-body">
  100. <view
  101. v-for="item in oaList"
  102. :key="item.type"
  103. class="quick-item"
  104. @click="handleAdd(item)">
  105. <image :src="$static(item.icon)" class="img" />
  106. <text class="text">
  107. {{ item.label }}
  108. </text>
  109. <image
  110. :src="$static('images/icon/add_primary.png')"
  111. class="control-icon" />
  112. </view>
  113. </view>
  114. </view>
  115. </scroll-view>
  116. <!-- #ifdef MP-WEIXIN -->
  117. <view class="footer-btn-group">
  118. <button class="button" @click="handleSave">
  119. 保存
  120. </button>
  121. </view>
  122. <!-- #endif -->
  123. </view>
  124. </view>
  125. </template>
  126. <script>
  127. import { GetNavConfig, SetNavConfig } from '@/api/base.js'
  128. import { mapMutations } from 'vuex'
  129. import dragSortMixins from '@/components/wk-drag-sort/mixins.js'
  130. import { crmLibList, oaLibList, getCommonNavList } from '@/utils/data.js'
  131. import { DEFAULT_NAV_CONFIG } from '@/config.js'
  132. export default {
  133. name: 'HomeQuickConfig',
  134. mixins: [dragSortMixins],
  135. data() {
  136. return {
  137. routerQuery: {},
  138. navConfig: {},
  139. configList: DEFAULT_NAV_CONFIG.common
  140. }
  141. },
  142. computed: {
  143. crmList() {
  144. return crmLibList.filter(o => !this.configList.includes(o.typeNum))
  145. },
  146. oaList() {
  147. return oaLibList.filter(o => !this.configList.includes(o.typeNum))
  148. },
  149. sortList() {
  150. return getCommonNavList(this.configList)
  151. }
  152. },
  153. onLoad(options) {
  154. this.routerQuery = options
  155. this.initCom()
  156. },
  157. methods: {
  158. ...mapMutations({
  159. setNavFooter: 'user/SET_NAV_FOOTER'
  160. }),
  161. initCom() {
  162. GetNavConfig().then(res => {
  163. this.navConfig = this.$isEmpty(res) ? {} : res[0]
  164. this.configList = this.navConfig.common || DEFAULT_NAV_CONFIG.common
  165. if (!this.$isEmpty(this.navConfig)) {
  166. uni.setStorageSync('navConfig', this.navConfig)
  167. }
  168. }).catch(() => {
  169. })
  170. },
  171. handleRemove(index) {
  172. this.clearMoveItem() // 悬浮结束
  173. this.configList.splice(index, 1)
  174. },
  175. handleSort(list) {
  176. this.configList = list.map(o => o.typeNum)
  177. },
  178. handleAdd(item) {
  179. if (this.configList.length >= 8) {
  180. this.$toast('首页只能添加8个常用功能')
  181. return
  182. }
  183. this.configList.push(item.typeNum)
  184. },
  185. handleSave() {
  186. const params = {
  187. ...this.navConfig,
  188. common: this.configList
  189. }
  190. SetNavConfig([params]).then(() => {
  191. this.setNavFooter(params)
  192. uni.setStorageSync('navConfig', params)
  193. this.$Router.navigateBack()
  194. }).catch(() => {})
  195. }
  196. }
  197. }
  198. </script>
  199. <style scoped lang="scss">
  200. .container {
  201. flex: 1;
  202. overflow: hidden;
  203. .quick-item {
  204. position: relative;
  205. width: calc(25% - 20rpx);
  206. height: 150rpx;
  207. flex-direction: column;
  208. box-shadow: 0px 6rpx 18rpx rgba(232, 232, 233, 0.77);
  209. border-radius: 16rpx;
  210. background-color: white;
  211. margin: 10rpx;
  212. @include center;
  213. .img {
  214. width: 64rpx;
  215. height: 64rpx;
  216. }
  217. .text {
  218. font-size: $wk-font-mini;
  219. margin-top: 10rpx;
  220. }
  221. .control-icon {
  222. position: absolute;
  223. top: 5rpx;
  224. right: 5rpx;
  225. width: 36rpx;
  226. height: 36rpx;
  227. }
  228. }
  229. .empty-item {
  230. width: calc(25% - 20rpx);
  231. height: 150rpx;
  232. box-shadow: unset;
  233. border: 1rpx dashed #999999;
  234. border-radius: 16rpx;
  235. margin: 10rpx;
  236. }
  237. .section {
  238. background-color: white;
  239. padding: 32rpx;
  240. .section-title {
  241. margin-bottom: 20rpx;
  242. .section-title__text {
  243. font-size: $wk-font-large;
  244. font-weight: bold;
  245. color: $dark;
  246. }
  247. .section-title__desc {
  248. font-size: $wk-font-base;
  249. color: $gray;
  250. }
  251. }
  252. .section-body {
  253. width: 100%;
  254. flex-wrap: wrap;
  255. @include left;
  256. }
  257. .wk-drag-sort {
  258. width: 100%;
  259. flex-wrap: wrap;
  260. @include left;
  261. .wk-drag-sort-item {
  262. width: calc(25% - 20rpx);
  263. height: 150rpx;
  264. margin: 10rpx;
  265. }
  266. .quick-item {
  267. width: 100%;
  268. height: 100%;
  269. margin: 0;
  270. }
  271. .move-item {
  272. position: fixed;
  273. visibility: hidden;
  274. z-index: 10;
  275. will-change: top left;
  276. }
  277. }
  278. }
  279. }
  280. </style>