Rap 原分销系统代码Web
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

fe5a950a388555f522abed2c03fc461b5a9bdf63.svn-base 6.9KB

5ヶ月前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <template>
  2. <div class="crud-opts">
  3. <span class="crud-opts-left">
  4. <!--左侧插槽-->
  5. <slot name="left" />
  6. <el-button
  7. v-if="crud.optShow.add"
  8. v-permission="permission.add"
  9. class="filter-item"
  10. size="mini"
  11. type="primary"
  12. icon="el-icon-plus"
  13. @click="crud.toAdd"
  14. >
  15. 新增
  16. </el-button>
  17. <el-button
  18. v-if="crud.optShow.edit"
  19. v-permission="permission.edit"
  20. class="filter-item"
  21. size="mini"
  22. type="success"
  23. icon="el-icon-edit"
  24. :disabled="crud.selections.length !== 1"
  25. @click="crud.toEdit(crud.selections[0])"
  26. >
  27. 修改
  28. </el-button>
  29. <el-button
  30. v-if="crud.optShow.del"
  31. slot="reference"
  32. v-permission="permission.del"
  33. class="filter-item"
  34. type="danger"
  35. icon="el-icon-delete"
  36. size="mini"
  37. :loading="crud.delAllLoading"
  38. :disabled="crud.selections.length === 0"
  39. @click="toDelete(crud.selections)"
  40. >
  41. 删除
  42. </el-button>
  43. <el-button
  44. v-if="crud.optShow.download"
  45. :loading="crud.downloadLoading"
  46. :disabled="!crud.data.length"
  47. class="filter-item"
  48. size="mini"
  49. type="warning"
  50. icon="el-icon-download"
  51. @click="crud.doExport"
  52. >导出</el-button>
  53. <!--右侧-->
  54. <slot name="right" />
  55. </span>
  56. <el-button-group class="crud-opts-right">
  57. <el-button
  58. size="mini"
  59. plain
  60. type="info"
  61. icon="el-icon-search"
  62. @click="toggleSearch()"
  63. />
  64. <el-button
  65. size="mini"
  66. icon="el-icon-refresh"
  67. @click="crud.refresh()"
  68. />
  69. <el-popover
  70. placement="bottom-end"
  71. width="150"
  72. trigger="click"
  73. >
  74. <el-button
  75. slot="reference"
  76. size="mini"
  77. icon="el-icon-s-grid"
  78. >
  79. <i
  80. class="fa fa-caret-down"
  81. aria-hidden="true"
  82. />
  83. </el-button>
  84. <el-checkbox
  85. v-model="allColumnsSelected"
  86. :indeterminate="allColumnsSelectedIndeterminate"
  87. @change="handleCheckAllChange"
  88. >
  89. 全选
  90. </el-checkbox>
  91. <el-checkbox
  92. v-for="item in tableColumns"
  93. :key="item.property"
  94. v-model="item.visible"
  95. @change="handleCheckedTableColumnsChange(item)"
  96. >
  97. {{ item.label }}
  98. </el-checkbox>
  99. </el-popover>
  100. </el-button-group>
  101. </div>
  102. </template>
  103. <script>
  104. import CRUD, { crud } from '@crud/crud'
  105. function sortWithRef(src, ref) {
  106. const result = Object.assign([], ref)
  107. let cursor = -1
  108. src.forEach(e => {
  109. const idx = result.indexOf(e)
  110. if (idx === -1) {
  111. cursor += 1
  112. result.splice(cursor, 0, e)
  113. } else {
  114. cursor = idx
  115. }
  116. })
  117. return result
  118. }
  119. export default {
  120. mixins: [crud()],
  121. props: {
  122. permission: {
  123. type: Object,
  124. default: () => { return {} }
  125. },
  126. hiddenColumns: {
  127. type: Array,
  128. default: () => { return [] }
  129. },
  130. ignoreColumns: {
  131. type: Array,
  132. default: () => { return [] }
  133. }
  134. },
  135. data() {
  136. return {
  137. tableColumns: [],
  138. allColumnsSelected: true,
  139. allColumnsSelectedIndeterminate: false,
  140. tableUnwatcher: null,
  141. // 忽略下次表格列变动
  142. ignoreNextTableColumnsChange: false
  143. }
  144. },
  145. watch: {
  146. 'crud.props.table'() {
  147. this.updateTableColumns()
  148. this.tableColumns.forEach(column => {
  149. if (this.hiddenColumns.indexOf(column.property) !== -1) {
  150. column.visible = false
  151. this.updateColumnVisible(column)
  152. }
  153. })
  154. },
  155. 'crud.props.table.store.states.columns'() {
  156. this.updateTableColumns()
  157. }
  158. },
  159. created() {
  160. this.crud.updateProp('searchToggle', true)
  161. },
  162. methods: {
  163. updateTableColumns() {
  164. const table = this.crud.getTable()
  165. if (!table) {
  166. this.tableColumns = []
  167. return
  168. }
  169. let cols = null
  170. const columnFilter = e => e && e.type === 'default' && e.property && this.ignoreColumns.indexOf(e.property) === -1
  171. const refCols = table.columns.filter(columnFilter)
  172. if (this.ignoreNextTableColumnsChange) {
  173. this.ignoreNextTableColumnsChange = false
  174. return
  175. }
  176. this.ignoreNextTableColumnsChange = false
  177. const columns = []
  178. const fullTableColumns = table.$children.map(e => e.columnConfig).filter(columnFilter)
  179. cols = sortWithRef(fullTableColumns, refCols)
  180. cols.forEach(config => {
  181. const column = {
  182. property: config.property,
  183. label: config.label,
  184. visible: refCols.indexOf(config) !== -1
  185. }
  186. columns.push(column)
  187. })
  188. this.tableColumns = columns
  189. },
  190. toDelete(datas) {
  191. this.$confirm(`确认删除选中的${datas.length}条数据?`, '提示', {
  192. confirmButtonText: '确定',
  193. cancelButtonText: '取消',
  194. type: 'warning'
  195. }).then(() => {
  196. this.crud.delAllLoading = true
  197. this.crud.doDelete(datas)
  198. }).catch(() => {
  199. })
  200. },
  201. handleCheckAllChange(val) {
  202. if (val === false) {
  203. this.allColumnsSelected = true
  204. return
  205. }
  206. this.tableColumns.forEach(column => {
  207. if (!column.visible) {
  208. column.visible = true
  209. this.updateColumnVisible(column)
  210. }
  211. })
  212. this.allColumnsSelected = val
  213. this.allColumnsSelectedIndeterminate = false
  214. },
  215. handleCheckedTableColumnsChange(item) {
  216. let totalCount = 0
  217. let selectedCount = 0
  218. this.tableColumns.forEach(column => {
  219. ++totalCount
  220. selectedCount += column.visible ? 1 : 0
  221. })
  222. if (selectedCount === 0) {
  223. this.crud.notify('请至少选择一列', CRUD.NOTIFICATION_TYPE.WARNING)
  224. this.$nextTick(function() {
  225. item.visible = true
  226. })
  227. return
  228. }
  229. this.allColumnsSelected = selectedCount === totalCount
  230. this.allColumnsSelectedIndeterminate = selectedCount !== totalCount && selectedCount !== 0
  231. this.updateColumnVisible(item)
  232. },
  233. updateColumnVisible(item) {
  234. const table = this.crud.props.table
  235. const vm = table.$children.find(e => e.prop === item.property)
  236. const columnConfig = vm.columnConfig
  237. if (item.visible) {
  238. // 找出合适的插入点
  239. const columnIndex = this.tableColumns.indexOf(item)
  240. vm.owner.store.commit('insertColumn', columnConfig, columnIndex + 1, null)
  241. } else {
  242. vm.owner.store.commit('removeColumn', columnConfig, null)
  243. }
  244. this.ignoreNextTableColumnsChange = true
  245. },
  246. toggleSearch() {
  247. this.crud.props.searchToggle = !this.crud.props.searchToggle
  248. }
  249. }
  250. }
  251. </script>
  252. <style>
  253. .crud-opts {
  254. padding: 4px 0;
  255. display: -webkit-flex;
  256. display: flex;
  257. align-items: center;
  258. }
  259. .crud-opts .crud-opts-right {
  260. margin-left: auto;
  261. }
  262. .crud-opts .crud-opts-right span {
  263. float: left;
  264. }
  265. </style>