You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

248 lines
6.7 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="gitem in groupList">
  35. <view :key="gitem[0]" class="margin-bottom">
  36. <!-- 区块标题 -->
  37. <l-title>{{ gitem[0] }}</l-title>
  38. <!-- 按钮组 -->
  39. <view class="function-list cu-list grid no-border col-4">
  40. <view
  41. v-for="(item, index) in gitem[1]"
  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. import { forEach } from 'lodash'
  76. export default {
  77. data() {
  78. return {
  79. allList: [],
  80. myList: [],
  81. editList: [],
  82. searchText: '',
  83. focus: false,
  84. edit: false
  85. }
  86. },
  87. async onLoad({ search }) {
  88. await this.init(search)
  89. },
  90. methods: {
  91. // 页面初始化
  92. async init(search) {
  93. this.focus = !!search
  94. this.LOADING('加载菜单中…')
  95. // 同时发出请求,获取“所有功能按钮列表”和“我的功能按钮列表”
  96. const [allList, myList] = await Promise.all([
  97. this.HTTP_GET('learun/adms/function/list').then(result => result.data),
  98. this.HTTP_GET('learun/adms/function/mylist')
  99. ])
  100. this.myList = myList.filter(t => allList.find(item => item.F_Id === t))
  101. this.allList = allList.map(item => {
  102. const icon = item.F_Icon ? item.F_Icon.replace(`iconfont icon-`, ``) : ''
  103. const existsIcon = this.getUiIcons().some(t => t === icon)
  104. return {
  105. ...item,
  106. icon: existsIcon ? icon : 'roundright'
  107. }
  108. })
  109. this.HIDE_LOADING()
  110. },
  111. // 点击编辑按钮,开启编辑模式
  112. async editClick() {
  113. if (!this.edit) {
  114. this.editList = [...this.myList]
  115. this.edit = true
  116. return
  117. }
  118. const success = await this.HTTP_POST(
  119. 'learun/adms/function/mylist/update',
  120. this.editList.join(','),
  121. '「我的应用」列表更新失败'
  122. )
  123. if (!success) {
  124. this.editList = [...this.myList]
  125. this.edit = false
  126. return
  127. }
  128. this.myList = [...this.editList]
  129. this.edit = false
  130. this.EMIT('home-list-change')
  131. },
  132. // 获取按钮图标背景色(已在列表中的为橙色,不在的为蓝色)
  133. funcListIconColor(item) {
  134. if (this.edit) {
  135. return this.editList.includes(item.F_Id) ? '#fe955c' : '#62bbff'
  136. }
  137. return this.myList.includes(item.F_Id) ? '#fe955c' : '#62bbff'
  138. },
  139. // 点击按钮
  140. funcListClick(item) {
  141. if (item.F_IsSystem === 2) {
  142. this.NAV_TO(`/pages/customapp/list?formId=${item.F_FormId}`, item, true)
  143. return
  144. }
  145. this.NAV_TO(`/pages/${item.F_Url}/list`)
  146. },
  147. // 取消编辑按钮
  148. cancelClick() {
  149. this.edit = false
  150. },
  151. // 我的应用列表:点击移出按钮
  152. removeClick(id) {
  153. this.editList = without(this.editList, id)
  154. },
  155. // 编辑模式,功能区点击添加/移除按钮
  156. itemClick(id) {
  157. if (this.editList.includes(id)) {
  158. this.editList = without(this.editList, id)
  159. return
  160. }
  161. this.editList = concat(this.editList, id)
  162. },
  163. // 菜单分组
  164. groupBy_(arr,field,typeTable){
  165. let res = groupBy(arr, field)
  166. let cateArr = []
  167. let res_ = []
  168. forEach(arr,(v,i)=>{
  169. if(!cateArr.includes(v[field])){
  170. cateArr.push(v[field])
  171. res_.push([typeTable[v[field]],res[v[field]]])
  172. }
  173. })
  174. return res_
  175. }
  176. },
  177. computed: {
  178. // 我的应用列表
  179. myListDisplay() {
  180. const list = this.edit ? this.editList : this.myList
  181. return list.reduce((list, id) => [...list, this.allList.find(t => t.F_Id === id)], [])
  182. },
  183. // 获取列表分组
  184. groupList() {
  185. const typeTable = mapValues(keyBy(Object.values(this.GET_GLOBAL('dataDictionary')?this.GET_GLOBAL('dataDictionary').function:()=>{}), 'value'), 'text')
  186. return this.groupBy_(this.allList.filter(item => item.F_Name.includes(this.searchText)), 'F_Type',typeTable)
  187. }
  188. }
  189. }
  190. </script>
  191. <style lang="less" scoped>
  192. .function-list {
  193. padding-bottom: 0;
  194. .cu-item {
  195. .app-item {
  196. border-radius: 50%;
  197. height: 45px;
  198. width: 45px;
  199. }
  200. }
  201. }
  202. </style>
  203. <style lang="less">
  204. #more {
  205. .function-list .cu-item text[class*='cuIcon'] {
  206. margin-top: 0 !important;
  207. }
  208. }
  209. page {
  210. padding-top: 100rpx;
  211. }
  212. </style>