txtView.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <div class="txtView" v-loading="loading">
  3. <div class="tv_content" v-text="content"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import "../../../../common/aws-sdk-2.235.1.min.js";
  8. const getFile = url => {
  9. return new Promise((resolve, reject) => {
  10. var credentials = {
  11. accessKeyId: "AKIATLPEDU37QV5CHLMH",
  12. secretAccessKey: "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"
  13. }; //秘钥形式的登录上传
  14. window.AWS.config.update(credentials);
  15. window.AWS.config.region = "cn-northwest-1"; //设置区域
  16. let url2 = url;
  17. let _url2 = "";
  18. if (
  19. url2.indexOf("https://view.officeapps.live.com/op/view.aspx?src=") != -1
  20. ) {
  21. _url2 = url2.split(
  22. "https://view.officeapps.live.com/op/view.aspx?src="
  23. )[1];
  24. } else {
  25. _url2 = url2;
  26. }
  27. var s3 = new window.AWS.S3({ params: { Bucket: "ccrb" } });
  28. let name = decodeURIComponent(
  29. _url2.split("https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/")[1]
  30. );
  31. var params = {
  32. Bucket: "ccrb",
  33. Key: name
  34. };
  35. s3.getObject(params, function(err, data) {
  36. if (err) {
  37. console.log(err, err.stack);
  38. resolve({ data: 1 });
  39. } else {
  40. const fileContent = data.Body.toString("utf-8");
  41. resolve({ data: fileContent });
  42. } // sxuccessful response
  43. });
  44. // axios({
  45. });
  46. };
  47. export default {
  48. props: {
  49. url: {
  50. type: String,
  51. default: ""
  52. },
  53. },
  54. data(){
  55. return{
  56. content:"",
  57. loading:""
  58. }
  59. },
  60. methods: {
  61. getTxtContent() {
  62. if(!this.url)return;
  63. this.loading = true;
  64. getFile(this.url).then(res=>{
  65. this.loading = false;
  66. this.content = res.data;
  67. })
  68. },
  69. },
  70. mounted(){
  71. this.getTxtContent();
  72. }
  73. };
  74. </script>
  75. <style scoped>
  76. .txtView{
  77. width: 100%;
  78. height: 100%;
  79. box-sizing: border-box;
  80. background-color: #ececec;
  81. padding: 20px;
  82. }
  83. .tv_content{
  84. width: 100%;
  85. height: 100%;
  86. box-sizing: border-box;
  87. background-color: #fff;
  88. overflow: auto;
  89. word-wrap: break-word;
  90. border-radius: 3px;
  91. white-space: pre;
  92. }
  93. </style>