瀏覽代碼

最新版

李昌恒 6 年之前
父節點
當前提交
a461ae2f85
共有 4 個文件被更改,包括 426 次插入420 次删除
  1. 3 2
      pc_chat/config/index.js
  2. 87 0
      pc_chat/src/assets/publicMethods.js
  3. 334 415
      pc_chat/src/components/chat.vue
  4. 2 3
      pc_chat/src/main.js

+ 3 - 2
pc_chat/config/index.js

@@ -12,7 +12,8 @@ module.exports = {
     assetsPublicPath: '/',
     proxyTable: {
       '/api': {
-        target: 'http://192.168.2.186:8090', // 后台访问地址
+        target:'http://103.108.43.176:8080',  // 后台访问地址
+        changeOrigin: true,
         pathRewrite: {
           '^/api': ''
         }
@@ -21,7 +22,7 @@ module.exports = {
 
     // Various Dev Server settings
     host: 'localhost', // can be overwritten by process.env.HOST
-    port: 8000, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
+    port: 8088, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
     autoOpenBrowser: false,
     errorOverlay: true,
     notifyOnErrors: true,

+ 87 - 0
pc_chat/src/assets/publicMethods.js

@@ -0,0 +1,87 @@
+export default {
+    //获取图片
+    imgPreview(file, callback) {
+        let self = this;
+        //判断支不支持FileReader
+        if (!file || !window.FileReader) return;
+        if (/^image/.test(file.type)) {
+            //创建一个reader
+            let reader = new FileReader();
+
+            //将图片转成base64格式
+            reader.readAsDataURL(file);
+            //读取成功后的回调
+            reader.onloadend = function() {
+                let result = this.result;
+                let img = new Image();
+                img.src = result;
+                // self.imgSrc = result;
+                img.onload = function() {
+                    let data = self.compress(img);
+                    let blob = self.dataURItoBlob(data);
+                    console.log(blob);
+                    var formData = new FormData();
+                    formData.append("file", blob);
+                    let config = {
+                        headers: { "Content-Type": "multipart/form-data" }
+                    };
+                    //图片预览,配置文件,formData数据;
+                    callback && callback(data,config,formData);
+                    // console.log(formData.file);
+                    // console.log(formData);
+
+                  
+
+                    // 数据结构请求
+                };
+            };
+        }
+    },
+    // 压缩图片
+    compress(img) {
+        let canvas = document.createElement("canvas");
+        let ctx = canvas.getContext("2d");
+        // let initSize = img.src.length;
+        let width = img.width;
+        let height = img.height;
+        canvas.width = width;
+        canvas.height = height;
+        // 铺底色
+        ctx.fillStyle = "#fff";
+        ctx.fillRect(0, 0, canvas.width, canvas.height);
+        ctx.drawImage(img, 0, 0, width, height);
+
+        //进行最小压缩
+        let ndata = canvas.toDataURL("image/jpeg", 0.4);
+        // console.log("*******压缩后的图片大小*******");
+        // console.log(ndata)
+        // console.log(ndata.length);
+        return ndata;
+    },
+
+    // base64转成bolb对象
+    dataURItoBlob(base64Data) {
+        var byteString;
+        if (base64Data.split(",")[0].indexOf("base64") >= 0)
+            byteString = atob(base64Data.split(",")[1]);
+        else byteString = unescape(base64Data.split(",")[1]);
+        var mimeString = base64Data
+            .split(",")[0]
+            .split(":")[1]
+            .split(";")[0];
+        var ia = new Uint8Array(byteString.length);
+        for (var i = 0; i < byteString.length; i++) {
+            ia[i] = byteString.charCodeAt(i);
+        }
+        return new Blob([ia], { type: mimeString });
+    },
+    //获取url参数
+    getQueryString(name) {
+        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
+        var r = window.location.search.substr(1).match(reg);
+        if (r != null) {
+            return unescape(r[2]);
+        }
+        return null;
+    } 
+}

文件差異過大導致無法顯示
+ 334 - 415
pc_chat/src/components/chat.vue


+ 2 - 3
pc_chat/src/main.js

@@ -5,15 +5,14 @@ import App from './App'
 import ElementUI from 'element-ui';
 
 import 'element-ui/lib/theme-chalk/index.css';
-import publicMethods from '../static/publicMethods';
+import publicMethods from './assets/publicMethods';
 import md5 from '../static/md5';
 Vue.use(ElementUI);
 //  引入api
 import axios from 'axios' // 接口封装,请求拦截
-import Qs from 'qs'
 Vue.prototype.$axios = axios
-Vue.prototype.$qs = Qs;
 Vue.prototype.$md5 = md5;
+Vue.prototype.$public = publicMethods;
 Vue.config.productionTip = false;
 // Vue.prototype.$axios.defaults.baseURL = 'http://192.168.2.186:8090'
 /* eslint-disable no-new */

部分文件因文件數量過多而無法顯示