List.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :showSync="false"
  6. :group-actions="groupActions"
  7. :single-actions="singleActions" />
  8. </template>
  9. <script>
  10. import { mapGetters } from 'vuex'
  11. import ListMixin from '@/mixins/list'
  12. import WindowsMixin from '@/mixins/windows'
  13. import GlobalSearchMixin from '@/mixins/globalSearch'
  14. import storage from '@/utils/storage'
  15. import { PRICE_COMPARA_KEY_SUFFIX } from '@Cloudenv/constants'
  16. import SingleActionsMixin from '../mixins/singleActions'
  17. import ColumnsMixin from '../mixins/columns'
  18. export default {
  19. name: 'PriceVMInstanceList',
  20. mixins: [WindowsMixin, ListMixin, GlobalSearchMixin, ColumnsMixin, SingleActionsMixin],
  21. props: {
  22. id: String,
  23. },
  24. data () {
  25. return {
  26. list: this.$list.createList(this, {
  27. id: this.id,
  28. resource: this.getData,
  29. }),
  30. groupActions: [
  31. {
  32. label: this.$t('common.action.create'),
  33. permission: 'server_create',
  34. action: (row) => {
  35. this.$router.push({
  36. path: '/pricecomparator/create',
  37. })
  38. },
  39. meta: () => {
  40. return {
  41. buttonType: 'primary',
  42. }
  43. },
  44. },
  45. {
  46. label: this.$t('cloudenv.text_108'),
  47. action: () => {
  48. let serverPriceComparator = storage.get(PRICE_COMPARA_KEY_SUFFIX) || []
  49. const selectedIds = this.list.selectedItems.map(v => v.id)
  50. serverPriceComparator = serverPriceComparator.filter(v => !selectedIds.includes(v.id))
  51. storage.set(PRICE_COMPARA_KEY_SUFFIX, serverPriceComparator)
  52. this.refreshData()
  53. },
  54. meta: () => {
  55. const ret = { validate: true }
  56. if (this.list.selectedItems.length <= 0) {
  57. ret.validate = false
  58. }
  59. return ret
  60. },
  61. },
  62. ],
  63. }
  64. },
  65. computed: {
  66. ...mapGetters(['userInfo', 'isAdminMode']),
  67. },
  68. created () {
  69. this.list.fetchData()
  70. },
  71. methods: {
  72. getData (params) {
  73. const data = storage.get(PRICE_COMPARA_KEY_SUFFIX) || []
  74. const list = data.filter(v => v.uid === this.userInfo.id)
  75. return {
  76. data: {
  77. data: list.slice(params.offset || 0, (params.offset || 0) + params.limit),
  78. total: list.length,
  79. offset: params.offset || 0,
  80. limit: params.limit,
  81. },
  82. }
  83. },
  84. refreshData () {
  85. this.list.refresh()
  86. },
  87. },
  88. }
  89. </script>
  90. <style lang="less" scoped>
  91. @import "../../../../../src/styles/less/theme";
  92. .hour {
  93. color: @error-color;
  94. font-size: 24px;
  95. }
  96. </style>