|
@@ -14,11 +14,21 @@
|
|
|
<view class="padding bg-white">
|
|
|
<u-parse :content="notication.content"></u-parse>
|
|
|
</view>
|
|
|
+ <u-cell-group :border="false">
|
|
|
+ <u-cell :border="false">
|
|
|
+ <u--text slot="title" :text="`附件`"></u--text>
|
|
|
+ </u-cell>
|
|
|
+ <u-cell v-for="(file, index) in fileArray" :key="index" :border="false">
|
|
|
+ <u--text slot="title" type="info" :text="getFileName(file)" @click="downloadFile(file)"></u--text>
|
|
|
+ </u-cell>
|
|
|
+ </u-cell-group>
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+ import fileService from "@/api/file/fileService"
|
|
|
import notifyService from "@/api/notify/notifyService";
|
|
|
+ import pick from "lodash.pick";
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
@@ -31,10 +41,57 @@
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
+ computed: {
|
|
|
+ fileArray() {
|
|
|
+ // 拆分字符串,以逗号为分隔符
|
|
|
+ return this.notication.files.split(',');
|
|
|
+ }
|
|
|
+ },
|
|
|
onLoad (option) {
|
|
|
notifyService.query({isSelf:true, id:option.id}).then((data)=>{
|
|
|
+ console.log('data', data)
|
|
|
this.notication = data
|
|
|
});
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ getFileName(file) {
|
|
|
+ // 通过字符串处理方法提取出文件名部分
|
|
|
+ const nameIndex = file.indexOf('name=');
|
|
|
+ if (nameIndex !== -1) {
|
|
|
+ return decodeURIComponent(file.slice(nameIndex + 5)); // +5 是为了跳过 'name=' 部分
|
|
|
+ }
|
|
|
+ return file;
|
|
|
+ },
|
|
|
+ downloadFile(file) {
|
|
|
+ if (file) {
|
|
|
+
|
|
|
+ const paramsString = file.split('?')[1];
|
|
|
+ const paramsArray = paramsString.split('&');
|
|
|
+
|
|
|
+ let uploadPath = '';
|
|
|
+ let name = '';
|
|
|
+
|
|
|
+ // 遍历参数数组并提取参数值
|
|
|
+ paramsArray.forEach(param => {
|
|
|
+ const [key, value] = param.split('=');
|
|
|
+ if (key === 'uploadPath') {
|
|
|
+ uploadPath = value;
|
|
|
+ } else if (key === 'name') {
|
|
|
+ name = value;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 使用 uni.downloadFile 下载文件
|
|
|
+ fileService.downloadUrl({
|
|
|
+ uploadPath: uploadPath,
|
|
|
+ name: name,
|
|
|
+ }).then((data) => {
|
|
|
+ console.log('data', data)
|
|
|
+ window.open(data, '_blank'); // 在新标签页或新窗口打开文件
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
</script>
|