index.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <div class="doc-icon">
  3. <img :src="srcUrl" :width="width" :height="height" />
  4. </div>
  5. </template>
  6. <script>
  7. import docIcons from './icons.js'
  8. import suffix from './suffix'
  9. export default {
  10. name: 'DocIcon',
  11. props: {
  12. width: {
  13. type: Number,
  14. default: 32,
  15. },
  16. height: {
  17. type: Number,
  18. default: 32,
  19. },
  20. type: {
  21. type: String,
  22. default: 'other',
  23. },
  24. src: {
  25. type: String,
  26. default: '',
  27. },
  28. },
  29. data() {
  30. return {
  31. docIcons,
  32. typeIndex: '',
  33. }
  34. },
  35. computed: {
  36. srcUrl() {
  37. return this.src ? this.src : this.docIcons[this.typeIndex]
  38. },
  39. },
  40. watch: {
  41. type: {
  42. immediate: true,
  43. handler: function () {
  44. if (suffix.video.includes(this.type)) {
  45. this.typeIndex = 'video'
  46. } else if (suffix.word.includes(this.type)) {
  47. this.typeIndex = 'word'
  48. } else if (suffix.ppt.includes(this.type)) {
  49. this.typeIndex = 'ppt'
  50. } else if (suffix.excel.includes(this.type)) {
  51. this.typeIndex = 'excel'
  52. } else if (this.docIcons[this.type]) {
  53. this.typeIndex = this.type
  54. } else {
  55. this.typeIndex = 'other'
  56. }
  57. },
  58. },
  59. },
  60. }
  61. </script>
  62. <style scoped>
  63. .doc-icon {
  64. font-size: 0;
  65. display: inline-block;
  66. vertical-align: middle;
  67. }
  68. .doc-icon img {
  69. display: block;
  70. }
  71. </style>