Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

236 wiersze
6.4 KiB

  1. <template>
  2. <view class="page" id="more">
  3. <!-- 顶部搜索栏 -->
  4. <l-banner v-model="searchText" :focus="focus" placeholder="搜索应用名" type="search" noSearchButton fill fixed />
  5. <!-- 「我的应用」列表 -->
  6. <l-title v-if="searchText.length <= 0">我的应用</l-title>
  7. <view v-if="searchText.length <= 0" class="col-4 function-list cu-list grid no-border">
  8. <view
  9. v-for="(item, index) in myListDisplay"
  10. :key="index"
  11. class="cu-item text-center flex flex-wrap justify-center align-center"
  12. >
  13. <!-- 图标 -->
  14. <view
  15. @click="funcListClick(item)"
  16. style="background-color: #fe955c;"
  17. class="app-item align-center flex flex-wrap justify-center align-center"
  18. >
  19. <l-icon :type="item.icon" color="white" class="text-sl" />
  20. </view>
  21. <text>{{ item && item.F_Name }}</text>
  22. <!-- 图标下方按钮 -->
  23. <l-button v-if="edit" @click="removeClick(item.F_Id)" line="red" class="margin-top-sm">移出</l-button>
  24. </view>
  25. </view>
  26. <!-- 操作区按钮 -->
  27. <view v-if="searchText.length <= 0" class="padding-lr padding-bottom bg-white margin-bottom">
  28. <l-button @click="editClick" :line="edit ? 'green' : 'blue'" block>
  29. {{ edit ? '完成编辑' : '编辑“我的应用”列表' }}
  30. </l-button>
  31. <l-button v-if="edit" @click="cancelClick" line="red" class="margin-top block" block>放弃编辑</l-button>
  32. </view>
  33. <!-- 分块显示功能区 -->
  34. <template v-for="(group, title) in groupList">
  35. <view :key="title" class="margin-bottom">
  36. <!-- 区块标题 -->
  37. <l-title>{{ title }}</l-title>
  38. <!-- 按钮组 -->
  39. <view class="function-list cu-list grid no-border col-4">
  40. <view
  41. v-for="(item, index) in group"
  42. :key="index"
  43. class="cu-item text-center flex flex-wrap justify-center align-center"
  44. >
  45. <view
  46. @click="funcListClick(item)"
  47. :style="{ backgroundColor: funcListIconColor(item) }"
  48. class="app-item align-center flex flex-wrap justify-center align-center"
  49. >
  50. <l-icon :type="item.icon" color="white" class="text-sl" />
  51. </view>
  52. <text>{{ item && item.F_Name }}</text>
  53. <!-- 编辑模式按钮 -->
  54. <l-button
  55. v-if="edit"
  56. @click="itemClick(item.F_Id)"
  57. :line="editList.includes(item.F_Id) ? 'red' : 'green'"
  58. class="margin-top-sm"
  59. >
  60. {{ editList.includes(item.F_Id) ? '移出' : '添加' }}
  61. </l-button>
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. </view>
  67. </template>
  68. <script>
  69. import without from 'lodash/without'
  70. import concat from 'lodash/concat'
  71. import keyBy from 'lodash/keyBy'
  72. import mapKeys from 'lodash/mapKeys'
  73. import mapValues from 'lodash/mapValues'
  74. import groupBy from 'lodash/groupBy'
  75. export default {
  76. data() {
  77. return {
  78. allList: [],
  79. myList: [],
  80. editList: [],
  81. searchText: '',
  82. focus: false,
  83. edit: false
  84. }
  85. },
  86. async onLoad({ search }) {
  87. await this.init(search)
  88. },
  89. methods: {
  90. // 页面初始化
  91. async init(search) {
  92. this.focus = !!search
  93. this.LOADING('加载菜单中…')
  94. // 同时发出请求,获取“所有功能按钮列表”和“我的功能按钮列表”
  95. const [allList, myList] = await Promise.all([
  96. this.HTTP_GET('learun/adms/function/list').then(result => result.data),
  97. this.HTTP_GET('learun/adms/function/mylist')
  98. ])
  99. this.myList = myList.filter(t => allList.find(item => item.F_Id === t))
  100. this.allList = allList.map(item => {
  101. const icon = item.F_Icon ? item.F_Icon.replace(`iconfont icon-`, ``) : ''
  102. const existsIcon = this.getUiIcons().some(t => t === icon)
  103. return {
  104. ...item,
  105. icon: existsIcon ? icon : 'roundright'
  106. }
  107. })
  108. this.HIDE_LOADING()
  109. },
  110. // 点击编辑按钮,开启编辑模式
  111. async editClick() {
  112. if (!this.edit) {
  113. this.editList = [...this.myList]
  114. this.edit = true
  115. return
  116. }
  117. const success = await this.HTTP_POST(
  118. 'learun/adms/function/mylist/update',
  119. this.editList.join(','),
  120. '「我的应用」列表更新失败'
  121. )
  122. if (!success) {
  123. this.editList = [...this.myList]
  124. this.edit = false
  125. return
  126. }
  127. this.myList = [...this.editList]
  128. this.edit = false
  129. this.EMIT('home-list-change')
  130. },
  131. // 获取按钮图标背景色(已在列表中的为橙色,不在的为蓝色)
  132. funcListIconColor(item) {
  133. if (this.edit) {
  134. return this.editList.includes(item.F_Id) ? '#fe955c' : '#62bbff'
  135. }
  136. return this.myList.includes(item.F_Id) ? '#fe955c' : '#62bbff'
  137. },
  138. // 点击按钮
  139. funcListClick(item) {
  140. if (item.F_IsSystem === 2) {
  141. this.NAV_TO(`/pages/customapp/list?formId=${item.F_FormId}`, item, true)
  142. return
  143. }
  144. this.NAV_TO(`/pages/${item.F_Url}/list`)
  145. },
  146. // 取消编辑按钮
  147. cancelClick() {
  148. this.edit = false
  149. },
  150. // 我的应用列表:点击移出按钮
  151. removeClick(id) {
  152. this.editList = without(this.editList, id)
  153. },
  154. // 编辑模式,功能区点击添加/移除按钮
  155. itemClick(id) {
  156. if (this.editList.includes(id)) {
  157. this.editList = without(this.editList, id)
  158. return
  159. }
  160. this.editList = concat(this.editList, id)
  161. }
  162. },
  163. computed: {
  164. // 我的应用列表
  165. myListDisplay() {
  166. const list = this.edit ? this.editList : this.myList
  167. return list.reduce((list, id) => [...list, this.allList.find(t => t.F_Id === id)], [])
  168. },
  169. // 获取列表分组
  170. groupList() {
  171. const typeTable = mapValues(keyBy(Object.values(this.GET_GLOBAL('dataDictionary').function), 'value'), 'text')
  172. return mapKeys(
  173. groupBy(this.allList.filter(item => item.F_Name.includes(this.searchText)), 'F_Type'),
  174. (v, k) => typeTable[k]
  175. )
  176. }
  177. }
  178. }
  179. </script>
  180. <style lang="less" scoped>
  181. .function-list {
  182. padding-bottom: 0;
  183. .cu-item {
  184. .app-item {
  185. border-radius: 50%;
  186. height: 45px;
  187. width: 45px;
  188. }
  189. }
  190. }
  191. </style>
  192. <style lang="less">
  193. #more {
  194. .function-list .cu-item text[class*='cuIcon'] {
  195. margin-top: 0 !important;
  196. }
  197. }
  198. page {
  199. padding-top: 100rpx;
  200. }
  201. </style>