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.

120 lines
2.8 KiB

  1. <template>
  2. <v-data-table
  3. :value="selected"
  4. :headers="headers"
  5. :items="items"
  6. :search="search"
  7. :loading="loading"
  8. loading-text="Loading... Please wait"
  9. item-key="id"
  10. show-select
  11. @input="updateSelected"
  12. >
  13. <template v-slot:top>
  14. <v-text-field
  15. v-model="search"
  16. prepend-inner-icon="search"
  17. label="Search"
  18. single-line
  19. hide-details
  20. filled
  21. />
  22. </template>
  23. <template v-slot:item.text="{ item }">
  24. <v-edit-dialog>
  25. {{ item.text }}
  26. <template v-slot:input>
  27. <v-text-field
  28. :value="item.text"
  29. :rules="labelNameRules"
  30. label="Edit"
  31. single-line
  32. @change="handleUpdateLabel({ id: item.id, text: $event })"
  33. />
  34. </template>
  35. </v-edit-dialog>
  36. </template>
  37. <template v-slot:item.suffix_key="{ item }">
  38. <v-edit-dialog>
  39. <div>{{ item.suffix_key }}</div>
  40. <template v-slot:input>
  41. <v-select
  42. :value="item.suffix_key"
  43. :items="keys"
  44. label="Key"
  45. @change="handleUpdateLabel({ id: item.id, suffix_key: $event })"
  46. />
  47. </template>
  48. </v-edit-dialog>
  49. </template>
  50. <template v-slot:item.background_color="{ item }">
  51. <v-edit-dialog>
  52. <v-chip
  53. :color="item.background_color"
  54. :text-color="textColor(item.background_color)"
  55. dark
  56. >
  57. {{ item.background_color }}
  58. </v-chip>
  59. <template v-slot:input>
  60. <v-color-picker
  61. :value="item.backgroundColor"
  62. :rules="colorRules"
  63. show-swatches
  64. hide-mode-switch
  65. width="800"
  66. mode="hexa"
  67. class="ma-2"
  68. @update:color="handleUpdateLabel({ id:item.id, background_color: $event.hex })"
  69. />
  70. </template>
  71. </v-edit-dialog>
  72. </template>
  73. </v-data-table>
  74. </template>
  75. <script>
  76. import { mapState, mapActions, mapMutations, mapGetters } from 'vuex'
  77. import { colorRules, labelNameRules } from '@/rules/index'
  78. import { idealColor } from '~/plugins/utils'
  79. export default {
  80. data() {
  81. return {
  82. search: '',
  83. colorRules,
  84. labelNameRules
  85. }
  86. },
  87. computed: {
  88. ...mapState('labels', ['items', 'selected', 'loading']),
  89. ...mapGetters('labels', ['headers']),
  90. keys() {
  91. return 'abcdefghijklmnopqrstuvwxyz'.split('')
  92. }
  93. },
  94. created() {
  95. this.getLabelList()
  96. },
  97. methods: {
  98. ...mapActions('labels', ['getLabelList', 'updateLabel']),
  99. ...mapMutations('labels', ['updateSelected']),
  100. handleUpdateLabel(payload) {
  101. const data = {
  102. projectId: this.$route.params.id,
  103. ...payload
  104. }
  105. this.updateLabel(data)
  106. },
  107. textColor(backgroundColor) {
  108. return idealColor(backgroundColor)
  109. }
  110. }
  111. }
  112. </script>