notificationDetail.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <view>
  3. <u-cell-group :border="false">
  4. <u-cell :border="false">
  5. <u--text slot="title" :text="`标题:${notication.title}`" ></u--text>
  6. </u-cell>
  7. <u-cell :border="false">
  8. <u--text slot="title" type="info" :text="`发布者:${notication.createBy.name},类型:${$dictUtils.getDictLabel('oa_notify_type', notication.type ,'')}`"></u--text>
  9. </u-cell>
  10. <u-cell>
  11. <u--text slot="title" type="info" :text="`发布时间: ${notication.createTime}`"></u--text>
  12. </u-cell>
  13. </u-cell-group>
  14. <view class="padding bg-white">
  15. <u-parse :content="notication.content"></u-parse>
  16. </view>
  17. <u-cell-group :border="false">
  18. <u-cell :border="false">
  19. <u--text slot="title" :text="`附件`"></u--text>
  20. </u-cell>
  21. <u-cell v-for="(file, index) in fileArray" :key="index" :border="false">
  22. <u--text slot="title" type="info" :text="getFileName(file)" @click="downloadFile(file)"></u--text>
  23. </u-cell>
  24. </u-cell-group>
  25. </view>
  26. </template>
  27. <script>
  28. import fileService from "@/api/file/fileService"
  29. import notifyService from "@/api/notify/notifyService";
  30. export default {
  31. data() {
  32. return {
  33. notication: {
  34. title: '',
  35. createTime: '',
  36. createBy: {
  37. name: ''
  38. }
  39. }
  40. }
  41. },
  42. computed: {
  43. fileArray() {
  44. // 拆分字符串,以逗号为分隔符
  45. return this.notication.files.split(',');
  46. }
  47. },
  48. onLoad (option) {
  49. notifyService.query({isSelf:true, id:option.id}).then((data)=>{
  50. this.notication = data
  51. });
  52. },
  53. methods: {
  54. getFileName(file) {
  55. // 通过字符串处理方法提取出文件名部分
  56. const nameIndex = file.indexOf('name=');
  57. if (nameIndex !== -1) {
  58. return decodeURIComponent(file.slice(nameIndex + 5)); // +5 是为了跳过 'name=' 部分
  59. }
  60. return file;
  61. },
  62. downloadFile(file) {
  63. if (file) {
  64. const paramsString = file.split('?')[1];
  65. const paramsArray = paramsString.split('&');
  66. let uploadPath = '';
  67. let name = '';
  68. // 遍历参数数组并提取参数值
  69. paramsArray.forEach(param => {
  70. const [key, value] = param.split('=');
  71. if (key === 'uploadPath') {
  72. uploadPath = value;
  73. } else if (key === 'name') {
  74. name = value;
  75. }
  76. });
  77. // 使用 uni.downloadFile 下载文件
  78. fileService.downloadUrl({
  79. uploadPath: uploadPath,
  80. name: name,
  81. }).then((data) => {
  82. // console.log('data', data)
  83. // window.open(data, '_blank'); // 在新标签页或新窗口打开文件
  84. // 在新窗口打开下载链接
  85. window.location.href = data;
  86. })
  87. }
  88. }
  89. }
  90. }
  91. </script>
  92. <style>
  93. </style>