8bd248c64e47bfb1e8c801b8e7dadd9c0325767a.svn-base 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <div>
  3. <a-modal
  4. :title="fileType === 'image' ? '图片上传' : '文件上传'"
  5. :width="width"
  6. :visible="visible"
  7. @ok="ok"
  8. cancelText="取消"
  9. @cancel="close">
  10. <!--style="top: 20px;"-->
  11. <j-upload :file-type="fileType" :value="filePath" @change="handleChange" :disabled="disabled" :number="number"></j-upload>
  12. </a-modal>
  13. </div>
  14. </template>
  15. <script>
  16. import { getFileAccessHttpUrl } from '@/api/manage';
  17. const getFileName=(path)=>{
  18. if(path.lastIndexOf("\\")>=0){
  19. let reg=new RegExp("\\\\","g");
  20. path = path.replace(reg,"/");
  21. }
  22. return path.substring(path.lastIndexOf("/")+1);
  23. }
  24. export default {
  25. name: 'JFilePop',
  26. components: { },
  27. props:{
  28. title:{
  29. type:String,
  30. default:'',
  31. required:false
  32. },
  33. position:{
  34. type:String,
  35. default:'right',
  36. required:false
  37. },
  38. height:{
  39. type:Number,
  40. default:200,
  41. required:false
  42. },
  43. width:{
  44. type:Number,
  45. default:520,
  46. required:false
  47. },
  48. popContainer:{
  49. type:String,
  50. default:'',
  51. required:false
  52. },
  53. disabled:{
  54. type:Boolean,
  55. default:false,
  56. required:false
  57. },
  58. number:{
  59. type:Number,
  60. required:false,
  61. default: 0
  62. }
  63. },
  64. data(){
  65. return {
  66. visible:false,
  67. filePath:'',
  68. id:'',
  69. fileType:'file'
  70. }
  71. },
  72. methods:{
  73. handleChange(value){
  74. this.filePath = value;
  75. },
  76. show(id,value,flag){
  77. this.id = id;
  78. this.filePath = value;
  79. this.visible=true
  80. if(flag === 'img'){
  81. this.fileType = 'image'
  82. }else{
  83. this.fileType = 'file'
  84. }
  85. },
  86. ok(){
  87. if(!this.filePath){
  88. this.$message.error("未上传任何文件")
  89. return false;
  90. }
  91. let arr = this.filePath.split(",")
  92. let obj = {
  93. name:getFileName(arr[0]),
  94. url:getFileAccessHttpUrl(arr[0]),
  95. path:this.filePath,
  96. status: 'done',
  97. id:this.id
  98. }
  99. this.$emit('ok',obj)
  100. this.visible=false
  101. },
  102. close(){
  103. this.visible=false
  104. }
  105. }
  106. }
  107. </script>
  108. <style scoped>
  109. </style>