ContentProtection.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <script>
  2. import {
  3. getContentProtection,
  4. updateContentProtection
  5. } from '@/api/external'
  6. export default {
  7. name: 'ContentProtection',
  8. props: {
  9. device: {
  10. type: Object,
  11. default: null
  12. }
  13. },
  14. data () {
  15. return {
  16. loading: true,
  17. error: false,
  18. open: false
  19. }
  20. },
  21. computed: {
  22. canEdit () {
  23. return this.accessSet.has(this.Access.MANAGE_DEVICES) || this.accessSet.has(this.Access.MANAGE_DEVICE)
  24. }
  25. },
  26. created () {
  27. this.getContentProtection()
  28. },
  29. methods: {
  30. getContentProtection () {
  31. this.loading = true
  32. this.error = false
  33. getContentProtection(this.device.id, { custom: true }).then(
  34. ({ data }) => {
  35. this.open = data ? data.protect : false
  36. },
  37. () => {
  38. this.error = true
  39. }
  40. ).finally(() => {
  41. this.loading = false
  42. })
  43. },
  44. toggle () {
  45. const open = !this.open
  46. updateContentProtection(this.device.id, open).then(() => {
  47. this.open = open
  48. })
  49. }
  50. },
  51. render (h) {
  52. if (this.loading) {
  53. return h('i', {
  54. class: 'el-icon-loading'
  55. })
  56. }
  57. if (this.error) {
  58. return h('el-link', {
  59. props: {
  60. type: 'warning'
  61. },
  62. on: {
  63. click: this.getContentProtection
  64. }
  65. }, ['获取失败,点击重试'])
  66. }
  67. if (this.canEdit) {
  68. return h('el-switch', {
  69. props: {
  70. value: this.open,
  71. 'active-color': '#13ce66',
  72. 'inactive-color': '#ff4949'
  73. },
  74. on: {
  75. change: this.toggle
  76. }
  77. })
  78. }
  79. return h('div', null, this.open ? '已启用' : '未启用')
  80. }
  81. }
  82. </script>