notificationDetail.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. import pick from "lodash.pick";
  31. export default {
  32. data() {
  33. return {
  34. notication: {
  35. title: '',
  36. createTime: '',
  37. createBy: {
  38. name: ''
  39. }
  40. }
  41. }
  42. },
  43. computed: {
  44. fileArray() {
  45. // 拆分字符串,以逗号为分隔符
  46. return this.notication.files.split(',');
  47. }
  48. },
  49. onLoad (option) {
  50. notifyService.query({isSelf:true, id:option.id}).then((data)=>{
  51. console.log('data', data)
  52. this.notication = data
  53. });
  54. },
  55. methods: {
  56. getFileName(file) {
  57. // 通过字符串处理方法提取出文件名部分
  58. const nameIndex = file.indexOf('name=');
  59. if (nameIndex !== -1) {
  60. return decodeURIComponent(file.slice(nameIndex + 5)); // +5 是为了跳过 'name=' 部分
  61. }
  62. return file;
  63. },
  64. downloadFile(file) {
  65. if (file) {
  66. const paramsString = file.split('?')[1];
  67. const paramsArray = paramsString.split('&');
  68. let uploadPath = '';
  69. let name = '';
  70. // 遍历参数数组并提取参数值
  71. paramsArray.forEach(param => {
  72. const [key, value] = param.split('=');
  73. if (key === 'uploadPath') {
  74. uploadPath = value;
  75. } else if (key === 'name') {
  76. name = value;
  77. }
  78. });
  79. // 使用 uni.downloadFile 下载文件
  80. fileService.downloadUrl({
  81. uploadPath: uploadPath,
  82. name: name,
  83. }).then((data) => {
  84. console.log('data', data)
  85. // window.open(data, '_blank'); // 在新标签页或新窗口打开文件
  86. // 在新窗口打开下载链接
  87. window.location.href = data;
  88. })
  89. }
  90. }
  91. }
  92. }
  93. </script>
  94. <style>
  95. </style>