123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <template>
- <div class="txtView" v-loading="loading">
- <div class="tv_content" v-text="content"></div>
- </div>
- </template>
- <script>
- import "../../../../common/aws-sdk-2.235.1.min.js";
- const getFile = url => {
- return new Promise((resolve, reject) => {
- var credentials = {
- accessKeyId: "AKIATLPEDU37QV5CHLMH",
- secretAccessKey: "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"
- }; //秘钥形式的登录上传
- window.AWS.config.update(credentials);
- window.AWS.config.region = "cn-northwest-1"; //设置区域
- let url2 = url;
- let _url2 = "";
- if (
- url2.indexOf("https://view.officeapps.live.com/op/view.aspx?src=") != -1
- ) {
- _url2 = url2.split(
- "https://view.officeapps.live.com/op/view.aspx?src="
- )[1];
- } else {
- _url2 = url2;
- }
- var s3 = new window.AWS.S3({ params: { Bucket: "ccrb" } });
- let name = decodeURIComponent(
- _url2.split("https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/")[1]
- );
- var params = {
- Bucket: "ccrb",
- Key: name
- };
- s3.getObject(params, function(err, data) {
- if (err) {
- console.log(err, err.stack);
- resolve({ data: 1 });
- } else {
- const fileContent = data.Body.toString("utf-8");
- resolve({ data: fileContent });
- } // sxuccessful response
- });
- // axios({
- });
- };
- export default {
- props: {
- url: {
- type: String,
- default: ""
- },
- },
- data(){
- return{
- content:"",
- loading:""
- }
- },
- methods: {
- getTxtContent() {
- if(!this.url)return;
- this.loading = true;
- getFile(this.url).then(res=>{
- this.loading = false;
- this.content = res.data;
- })
- },
- },
- watch:{
- url(newVal,oldVal){
- if(newVal!==oldVal){
- this.getTxtContent();
- }
- }
- },
- mounted(){
- this.getTxtContent();
- }
- };
- </script>
- <style scoped>
- .txtView{
- width: 100%;
- height: 100%;
- box-sizing: border-box;
- background-color: #ececec;
- padding: 0px 0px;
- }
- .tv_content{
- width: 100%;
- height: 100%;
- box-sizing: border-box;
- background-color: #fff;
- overflow: auto;
- word-wrap: break-word;
- border-radius: 3px;
- white-space: pre;
- box-sizing: border-box;
- padding: 10px;
- }
- </style>
|