Commit 299775af authored by 罗超's avatar 罗超

处理上传图片压缩

parent 2db9c308
......@@ -17,3 +17,4 @@ package-lock.json
*.njsproj
*.sln
yarn.lock
{
......@@ -4,79 +4,77 @@ const utils = require('./utils')
const config = require('../config')
const vueLoaderConfig = require('./vue-loader.conf')
function resolve (dir) {
return path.join(__dirname, '..', dir)
function resolve(dir) {
return path.join(__dirname, '..', dir)
}
module.exports = {
context: path.resolve(__dirname, '../'),
entry: {
app: './src/main.js'
},
output: {
path: config.build.assetsRoot,
filename: '[name].js',
publicPath: process.env.NODE_ENV === 'production'
? config.build.assetsPublicPath
: config.dev.assetsPublicPath
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('src'),
}
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('media/[name].[hash:7].[ext]')
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
context: path.resolve(__dirname, '../'),
entry: {
app: './src/main.js'
},
output: {
path: config.build.assetsRoot,
filename: '[name].js',
publicPath: process.env.NODE_ENV === 'production' ?
config.build.assetsPublicPath : config.dev.assetsPublicPath
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('src'),
}
}
]
},
node: {
// prevent webpack from injecting useless setImmediate polyfill because Vue
// source contains it (although only uses it if it's native).
setImmediate: false,
// prevent webpack from injecting mocks to Node native modules
// that does not make sense for the client
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty'
}
}
},
module: {
rules: [{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('media/[name].[hash:7].[ext]')
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
}
}
]
},
node: {
// prevent webpack from injecting useless setImmediate polyfill because Vue
// source contains it (although only uses it if it's native).
setImmediate: false,
// prevent webpack from injecting mocks to Node native modules
// that does not make sense for the client
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty'
}
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>微途超级商城</title>
</head>
<body>
</head>
<body>
<div id="app"></div>
</body>
</html>
<script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&key=OV7BZ-ZT3HP-6W3DE-LKHM3-RSYRV-ULFZV"></script>
</body>
</html>
<script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&key=OV7BZ-ZT3HP-6W3DE-LKHM3-RSYRV-ULFZV"></script>
\ No newline at end of file
......@@ -18,6 +18,7 @@
"echarts": "^4.8.0",
"element-ui": "^2.13.1",
"js-md5": "^0.7.3",
"lrz": "^4.9.40",
"vue": "^2.5.2",
"vue-router": "^3.0.1",
"vuedraggable": "^2.23.2"
......
......@@ -8,6 +8,7 @@ import ajaxPlug from './plug/index'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import echarts from 'echarts'
import lrz from 'lrz'
import '../static/UE/ueditor.config.js'
import '../static/UE/ueditor.all.js'
......@@ -17,17 +18,17 @@ import '../static/UE/ueditor.parse.min.js'
Vue.use(ElementUI);
import commonUtils from './assets/utils/commonUtils'
Vue.commonUtils = Vue.prototype.$commonUtils=commonUtils
Vue.commonUtils = Vue.prototype.$commonUtils = commonUtils
Vue.config.productionTip = false
Vue.http = Vue.prototype.$http = axios
Vue.prototype.$echarts = echarts
Vue.use(ajaxPlug)
/* eslint-disable no-new */
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
components: { App },
template: '<App/>'
})
el: '#app',
router,
components: { App },
template: '<App/>'
})
\ No newline at end of file
import md5 from 'js-md5'
export default {
install(Vue, options) {
Vue.prototype.md5 = md5;
//消息成功提示
Vue.prototype.Success = function (msg) {
this.$message({
message: msg,
duration: 2000,
type: "success"
});
},
//错误提示
Vue.prototype.Error = function (msg) {
this.$message({
message: msg,
duration: 2000,
type: "error"
});
},
install(Vue, options) {
Vue.prototype.md5 = md5;
//消息成功提示
Vue.prototype.Success = function(msg) {
this.$message({
message: msg,
duration: 2000,
type: "success"
});
},
//错误提示
Vue.prototype.Error = function(msg) {
this.$message({
message: msg,
duration: 2000,
type: "error"
});
},
//一般提示
Vue.prototype.Info = function (msg) {
this.$message({
message: msg,
duration: 2000,
type: "info"
});
},
//警告提示
Vue.prototype.Warning = function (msg) {
this.$message({
message: msg,
duration: 2000,
type: "warning"
});
},
//Confirm
Vue.prototype.Confirm = function (msg, callback) {
this.$confirm(msg, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
})
.then(() => {
if (typeof callback === 'function') {
callback();
//一般提示
Vue.prototype.Info = function(msg) {
this.$message({
message: msg,
duration: 2000,
type: "info"
});
},
//警告提示
Vue.prototype.Warning = function(msg) {
this.$message({
message: msg,
duration: 2000,
type: "warning"
});
},
//Confirm
Vue.prototype.Confirm = function(msg, callback) {
this.$confirm(msg, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
})
.then(() => {
if (typeof callback === 'function') {
callback();
}
})
.catch(() => {
this.Info("已取消操作");
});
},
//域名管理对象
Vue.prototype.domainManager = function() {
let domainUrl = '';
let javaUrl = 'http://192.168.2.65:8018';
domainUrl = "http://192.168.2.65";
//domainUrl = "https://localhost:5001";
let locationName = window.location.hostname;
if (locationName.indexOf('testmall.oytour') !== -1) {
domainUrl = "https://mallapi.oytour.com";
javaUrl = "http://property.oytour.com";
} else if (locationName.indexOf('oytour') !== -1) {
domainUrl = "https://mallapi.oytour.com";
javaUrl = "http://property.oytour.com";
}
var obj = {
//主地址npm
DomainUrl: domainUrl,
//资产管理
javaUrl: javaUrl,
//常用提交数据URL
PostUrl: domainUrl + "/api/common/post",
ImageUrl: 'https://viitto-1301420277.cos.ap-chengdu.myqcloud.com',
UploadFileUrl: domainUrl + '/api/File/LocalFileUploadImport',
UploadBlob: domainUrl + '/api/File/UploadBlob',
};
return obj;
},
//浏览器缓存
Vue.prototype.getLocalStorage = function() {
var localStorageData = window.localStorage["mall_userInfo"];
if (localStorageData !== undefined && localStorageData != 'undefined') {
return JSON.parse(localStorageData);
} else {
return null;
}
},
//验证只能输入2位小数【负数:isMinus传true】
Vue.prototype.checkPrice = function(item, filed, isMinus) {
var value = "" + item[filed]; //转字符串
var t = value.charAt(0);
value = value.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
value = value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
value = value
.replace(".", "$#$")
.replace(/\./g, "")
.replace("$#$", ".");
value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
//如果第一位是负号,则允许添加 如果不允许添加负号 可以把这块注释掉
//是否允许负数
if (isMinus && t == '-') {
value = '-' + value;
}
item[filed] = value;
}
})
.catch(() => {
this.Info("已取消操作");
});
},
//域名管理对象
Vue.prototype.domainManager = function () {
let domainUrl = '';
let javaUrl='http://192.168.2.65:8018';
//验证只能输入整数【负数:isMinus传true】
Vue.prototype.checkInteger = function(item, filed, isMinus) {
var value = "" + item[filed]; //转字符串
var t = value.charAt(0);
value = value.replace(this.$commonUtils.Regex.isInteger, "");
//是否允许负数
if (isMinus && t == '-') {
value = '-' + value;
}
item[filed] = value;
},
//是否是线上环境【发布时修改为true】
Vue.prototype.isOnline = function() {
return process.env.NODE_ENV !== 'development';
},
//文件类型数组
Vue.prototype.FileType = function() {
var fileTypeJson = {
//主地址npm
UserImg: "User", //用户相图片
//常用提交数据URL
GoodsImg: "Goods", //素材相关文件
SetImg: "Set", //用户相图片
};
return fileTypeJson;
},
//上传文件到云存储
Vue.prototype.UploadFileToTencent = function(path, fileObj, callback) {
// debugger;
console.log('filein...')
if (fileObj.type == "image/png" || fileObj.type == "image/jpeg") {
lrz(fileObj, {
width: 750,
quality: 0.8
})
.then(function(rst) {
//成功时执行
console.log(rst)
}).catch(function(error) {
this.uploadStart(path, fileObj, callback)
}).always(function() {
//不管成功或失败,都会执行
})
}
domainUrl = "http://192.168.2.214:8200";
//domainUrl = "https://localhost:5001";
let locationName = window.location.hostname;
if (locationName.indexOf('testmall.oytour') !== -1) {
domainUrl = "https://mallapi.oytour.com";
javaUrl="http://property.oytour.com";
} else if (locationName.indexOf('oytour') !== -1) {
domainUrl = "https://mallapi.oytour.com";
javaUrl="http://property.oytour.com";
}
var obj = {
//主地址npm
DomainUrl: domainUrl,
//资产管理
javaUrl: javaUrl,
//常用提交数据URL
PostUrl: domainUrl + "/api/common/post",
ImageUrl: 'https://viitto-1301420277.cos.ap-chengdu.myqcloud.com',
UploadFileUrl: domainUrl + '/api/File/LocalFileUploadImport',
UploadBlob: domainUrl + '/api/File/UploadBlob',
};
return obj;
},
//浏览器缓存
Vue.prototype.getLocalStorage = function () {
var localStorageData = window.localStorage["mall_userInfo"];
if (localStorageData !== undefined && localStorageData != 'undefined') {
return JSON.parse(localStorageData);
} else {
return null;
}
},
//验证只能输入2位小数【负数:isMinus传true】
Vue.prototype.checkPrice = function (item, filed, isMinus) {
var value = "" + item[filed]; //转字符串
var t = value.charAt(0);
value = value.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
value = value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
value = value
.replace(".", "$#$")
.replace(/\./g, "")
.replace("$#$", ".");
value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
//如果第一位是负号,则允许添加 如果不允许添加负号 可以把这块注释掉
//是否允许负数
if (isMinus && t == '-') {
value = '-' + value;
}
item[filed] = value;
}
//验证只能输入整数【负数:isMinus传true】
Vue.prototype.checkInteger = function (item, filed, isMinus) {
var value = "" + item[filed]; //转字符串
var t = value.charAt(0);
value = value.replace(this.$commonUtils.Regex.isInteger, "");
//是否允许负数
if (isMinus && t == '-') {
value = '-' + value;
}
item[filed] = value;
},
//是否是线上环境【发布时修改为true】
Vue.prototype.isOnline = function () {
return process.env.NODE_ENV !== 'development';
},
//文件类型数组
Vue.prototype.FileType = function () {
var fileTypeJson = {
//主地址npm
UserImg: "User", //用户相图片
//常用提交数据URL
GoodsImg: "Goods", //素材相关文件
SetImg: "Set", //用户相图片
};
return fileTypeJson;
},
//上传文件到云存储
Vue.prototype.UploadFileToTencent = function (path, fileObj, callback) {
//获取文件扩展名
var filename = fileObj.name;
var index = filename.lastIndexOf(".");
var suffix = filename.substr(index);
var timestamp1 = Date.parse(new Date()) + "_" + (Math.ceil(Math.random() * 1000));
let str = '';
if (this.isOnline()) {
str = "/Test"
}
var newFileName = str + '/Upload/' + path + "/" + timestamp1 + "" + suffix;
var uploadMsg = {
Bucket: "viitto-1301420277",
Region: "ap-chengdu",
/* 存储桶所在地域,必须字段 */
SecretId: "AKIDDPnbIzi8C1eqEOPP8dw6MNAg9H9ldDKd",
SecretKey: "PdcLtOjslUzNFYdU4OSI1fKtdHpFT2Ob",
};
var COS = require('cos-js-sdk-v5');
var cos = new COS({
SecretId: uploadMsg.SecretId,
SecretKey: uploadMsg.SecretKey,
});
cos.putObject({
Bucket: uploadMsg.Bucket,
Region: uploadMsg.Region, //存储桶所在地域,必须字段
Key: newFileName, //文件名
StorageClass: 'STANDARD',
Body: fileObj, // 上传文件对象
onProgress: function (progressData) {}
}, function (err, data) {
if (data && data.statusCode == 200) {
var uploadResult = {
resultCode: 1,
FileName: fileObj.name,
FileUrl: "http://" + data.Location
},
Vue.prototype.uploadStart = function(path, fileObj, callback) {
//获取文件扩展名
var filename = fileObj.name;
var index = filename.lastIndexOf(".");
var suffix = filename.substr(index);
var timestamp1 = Date.parse(new Date()) + "_" + (Math.ceil(Math.random() * 1000));
let str = '';
if (this.isOnline()) {
str = "/Test"
}
var newFileName = str + '/Upload/' + path + "/" + timestamp1 + "" + suffix;
var uploadMsg = {
Bucket: "viitto-1301420277",
Region: "ap-chengdu",
/* 存储桶所在地域,必须字段 */
SecretId: "AKIDDPnbIzi8C1eqEOPP8dw6MNAg9H9ldDKd",
SecretKey: "PdcLtOjslUzNFYdU4OSI1fKtdHpFT2Ob",
};
var COS = require('cos-js-sdk-v5');
var cos = new COS({
SecretId: uploadMsg.SecretId,
SecretKey: uploadMsg.SecretKey,
});
cos.putObject({
Bucket: uploadMsg.Bucket,
Region: uploadMsg.Region, //存储桶所在地域,必须字段
Key: newFileName, //文件名
StorageClass: 'STANDARD',
Body: fileObj, // 上传文件对象
onProgress: function(progressData) {}
}, function(err, data) {
if (data && data.statusCode == 200) {
var uploadResult = {
resultCode: 1,
FileName: fileObj.name,
FileUrl: "http://" + data.Location
}
if (callback) {
callback(uploadResult);
}
} else {
/*上传文件异常*/
console.log(err || data);
}
});
},
//公用跳转
Vue.prototype.CommonJump = function(path, obj) {
this.$router.push({
name: path,
query: obj
});
}
if (callback) {
callback(uploadResult);
//公用判断图片地址 判断是否包含http
Vue.prototype.getIconLink = function(url) {
let str = ''
if (url && url != '') {
if (url.indexOf('http') != -1) {
str = url
} else {
str = this.domainManager().ImageUrl + url;
}
return str;
}
}
} else {
/*上传文件异常*/
console.log(err || data);
}
});
},
//公用跳转
Vue.prototype.CommonJump = function (path, obj) {
this.$router.push({
name: path,
query: obj
});
}
//公用判断图片地址 判断是否包含http
Vue.prototype.getIconLink = function (url) {
let str = ''
if (url && url != '') {
if (url.indexOf('http') != -1) {
str = url
} else {
str = this.domainManager().ImageUrl + url;
}
return str;
}
}
//HTTP提交数据
Vue.prototype.apipost = function (cmd, msg, successCall, faildCall, isOnline) {
var apiurl = this.domainManager().DomainUrl + cmd;
var postData = this.GetPostData(cmd, msg, "");
this.$http.post(apiurl, postData, {
headers: {
'Content-Type': 'application/json',
'Referer-Viitto': this.$route.path
}
})
.then(res => {
if (res.data.resultCode == 10000 || res.data.resultCode == 10001) {
this.$router.push({
path: '/login'
});
} else if (res.resultCode == 10005) {
this.$router.go(-1);
} else {
successCall(res);
}
}, faildCall)
}
//获取请求参数
Vue.prototype.GetPostData = function (cmd, msg, newCmd) {
if (msg == null || msg == "") {
msg = {}
}
var timestamp = (new Date()).valueOf();
if (!localStorage.mall_userInfo && localStorage.mall_userInfo != "" &&
this.$route.path.toLowerCase() != "/login" &&
this.$route.path.toLowerCase() != "/register" &&
this.$route.path.toLowerCase() != "/forgetpassword"
) {
this.$router.push({
path: '/login'
})
}
var token = "";
var key = "";
var MallBaseId = "0"; //小程序ID
var TenantId = "0"; //商户Id
var EmpId = 0; //员工编号【员工登录时使用】
if (this.getLocalStorage() != null) {
token = this.getLocalStorage().Token;
key = this.getLocalStorage().SecretKey;
MallBaseId = this.getLocalStorage().MallBaseId;
TenantId = this.getLocalStorage().TenantId;
EmpId = this.getLocalStorage().EmpId;
}
var encodeMsg = encodeURIComponent(JSON.stringify(msg)).toLowerCase();
var md5Str = md5(`cmd=${cmd}&msg=${encodeMsg}&timestamp=${timestamp}&token=${token}&key=${key}`);
let tempLanguage = 0;
if (localStorage.language && localStorage.language != '') {
if (localStorage.language == "zh-TW") {
tempLanguage = 1;
} else if (localStorage.language == "Japanese") {
tempLanguage = 2;
}
}
var cmdStr = "";
if (newCmd) {
cmdStr = newCmd;
}
var postData = {
msg: msg,
timestamp: timestamp,
token: token,
sign: md5Str,
languageId: tempLanguage,
cmd: cmdStr,
MallBaseId: MallBaseId,
TenantId: TenantId,
EmpId: EmpId,
MiniAppId: "wxacd9f8cc3480d29e",
OpenId: "ow_7I5ZQKhAB66yvOTGI35Xk-Kmg",
// UserId:19992,
}
return postData
},
//HTTP提交数据资产
Vue.prototype.assetsApipost = function (cmd, msg, successCall, faildCall, isOnline) {
var apiurl = this.domainManager().DomainUrl + cmd;
var postData = this.GetAssetsPostData(cmd, msg, "");
this.$http.post(apiurl, postData, {
headers: {
'Content-Type': 'application/json',
'Referer-Viitto': this.$route.path
//HTTP提交数据
Vue.prototype.apipost = function(cmd, msg, successCall, faildCall, isOnline) {
var apiurl = this.domainManager().DomainUrl + cmd;
var postData = this.GetPostData(cmd, msg, "");
this.$http.post(apiurl, postData, {
headers: {
'Content-Type': 'application/json',
'Referer-Viitto': this.$route.path
}
})
.then(res => {
if (res.data.resultCode == 10000 || res.data.resultCode == 10001) {
this.$router.push({
path: '/login'
});
} else if (res.resultCode == 10005) {
this.$router.go(-1);
} else {
successCall(res);
}
}, faildCall)
}
})
.then(res => {
if (res.data.resultCode == 10000 || res.data.resultCode == 10001) {
this.$router.push({
path: '/login'
});
} else if (res.resultCode == 10005) {
this.$router.go(-1);
} else {
successCall(res);
//获取请求参数
Vue.prototype.GetPostData = function(cmd, msg, newCmd) {
if (msg == null || msg == "") {
msg = {}
}
var timestamp = (new Date()).valueOf();
if (!localStorage.mall_userInfo && localStorage.mall_userInfo != "" &&
this.$route.path.toLowerCase() != "/login" &&
this.$route.path.toLowerCase() != "/register" &&
this.$route.path.toLowerCase() != "/forgetpassword"
) {
this.$router.push({
path: '/login'
})
}
var token = "";
var key = "";
var MallBaseId = "0"; //小程序ID
var TenantId = "0"; //商户Id
var EmpId = 0; //员工编号【员工登录时使用】
if (this.getLocalStorage() != null) {
token = this.getLocalStorage().Token;
key = this.getLocalStorage().SecretKey;
MallBaseId = this.getLocalStorage().MallBaseId;
TenantId = this.getLocalStorage().TenantId;
EmpId = this.getLocalStorage().EmpId;
}
var encodeMsg = encodeURIComponent(JSON.stringify(msg)).toLowerCase();
var md5Str = md5(`cmd=${cmd}&msg=${encodeMsg}&timestamp=${timestamp}&token=${token}&key=${key}`);
let tempLanguage = 0;
if (localStorage.language && localStorage.language != '') {
if (localStorage.language == "zh-TW") {
tempLanguage = 1;
} else if (localStorage.language == "Japanese") {
tempLanguage = 2;
}
}
var cmdStr = "";
if (newCmd) {
cmdStr = newCmd;
}
var postData = {
msg: msg,
timestamp: timestamp,
token: token,
sign: md5Str,
languageId: tempLanguage,
cmd: cmdStr,
MallBaseId: MallBaseId,
TenantId: TenantId,
EmpId: EmpId,
MiniAppId: "wxacd9f8cc3480d29e",
OpenId: "ow_7I5ZQKhAB66yvOTGI35Xk-Kmg",
// UserId:19992,
}
return postData
},
//HTTP提交数据资产
Vue.prototype.assetsApipost = function(cmd, msg, successCall, faildCall, isOnline) {
var apiurl = this.domainManager().DomainUrl + cmd;
var postData = this.GetAssetsPostData(cmd, msg, "");
this.$http.post(apiurl, postData, {
headers: {
'Content-Type': 'application/json',
'Referer-Viitto': this.$route.path
}
})
.then(res => {
if (res.data.resultCode == 10000 || res.data.resultCode == 10001) {
this.$router.push({
path: '/login'
});
} else if (res.resultCode == 10005) {
this.$router.go(-1);
} else {
successCall(res);
}
}, faildCall)
}
}, faildCall)
}
//获取请求参数
Vue.prototype.GetAssetsPostData = function (cmd, msg, newCmd) {
if (msg == null || msg == "") {
msg = {}
}
var timestamp = (new Date()).valueOf();
if (!localStorage.mall_userInfo && localStorage.mall_userInfo != "" &&
this.$route.path.toLowerCase() != "/login" &&
this.$route.path.toLowerCase() != "/register" &&
this.$route.path.toLowerCase() != "/forgetpassword"
) {
this.$router.push({
path: '/login'
})
}
var token = "";
var key = "";
var MallBaseId = "0"; //小程序ID
var TenantId = "0"; //商户Id
var EmpId = 0; //员工编号【员工登录时使用】
var ERPGroupId = 0;
var ERPEmpId = 0;
var ERPBranchId = 0;
if (this.getLocalStorage() != null) {
token = this.getLocalStorage().Token;
key = this.getLocalStorage().SecretKey;
MallBaseId = this.getLocalStorage().MallBaseId;
TenantId = this.getLocalStorage().TenantId;
EmpId = this.getLocalStorage().EmpId;
ERPGroupId = this.getLocalStorage().ERPGroupId;
ERPEmpId = this.getLocalStorage().ERPEmpId;
ERPBranchId = this.getLocalStorage().ERPBranchId;
}
var encodeMsg = encodeURIComponent(JSON.stringify(msg)).toLowerCase();
var md5Str = md5(`cmd=${cmd}&msg=${encodeMsg}&timestamp=${timestamp}&token=${token}&key=${key}`);
let tempLanguage = 0;
if (localStorage.language && localStorage.language != '') {
if (localStorage.language == "zh-TW") {
tempLanguage = 1;
} else if (localStorage.language == "Japanese") {
tempLanguage = 2;
}
}
var cmdStr = "";
if (newCmd) {
cmdStr = newCmd;
}
var postData = {
msg: msg,
timestamp: timestamp,
token: token,
sign: md5Str,
languageId: tempLanguage,
cmd: cmdStr,
MallBaseId: MallBaseId,
TenantId: TenantId,
EmpId: EmpId,
ERPGroupId: ERPGroupId,
ERPEmpId: ERPEmpId,
ERPBranchId: ERPBranchId,
// MiniAppId:"wxacd9f8cc3480d29e",
// OpenId:"ow_7I5ZQKhAB66yvOTGI35Xk-Kmg",
// UserId:19992,
}
return postData
},
//获取请求参数
Vue.prototype.GetAssetsPostData = function(cmd, msg, newCmd) {
if (msg == null || msg == "") {
msg = {}
}
var timestamp = (new Date()).valueOf();
if (!localStorage.mall_userInfo && localStorage.mall_userInfo != "" &&
this.$route.path.toLowerCase() != "/login" &&
this.$route.path.toLowerCase() != "/register" &&
this.$route.path.toLowerCase() != "/forgetpassword"
) {
this.$router.push({
path: '/login'
})
}
var token = "";
var key = "";
var MallBaseId = "0"; //小程序ID
var TenantId = "0"; //商户Id
var EmpId = 0; //员工编号【员工登录时使用】
var ERPGroupId = 0;
var ERPEmpId = 0;
var ERPBranchId = 0;
if (this.getLocalStorage() != null) {
token = this.getLocalStorage().Token;
key = this.getLocalStorage().SecretKey;
MallBaseId = this.getLocalStorage().MallBaseId;
TenantId = this.getLocalStorage().TenantId;
EmpId = this.getLocalStorage().EmpId;
ERPGroupId = this.getLocalStorage().ERPGroupId;
ERPEmpId = this.getLocalStorage().ERPEmpId;
ERPBranchId = this.getLocalStorage().ERPBranchId;
}
var encodeMsg = encodeURIComponent(JSON.stringify(msg)).toLowerCase();
var md5Str = md5(`cmd=${cmd}&msg=${encodeMsg}&timestamp=${timestamp}&token=${token}&key=${key}`);
let tempLanguage = 0;
if (localStorage.language && localStorage.language != '') {
if (localStorage.language == "zh-TW") {
tempLanguage = 1;
} else if (localStorage.language == "Japanese") {
tempLanguage = 2;
}
}
var cmdStr = "";
if (newCmd) {
cmdStr = newCmd;
}
var postData = {
msg: msg,
timestamp: timestamp,
token: token,
sign: md5Str,
languageId: tempLanguage,
cmd: cmdStr,
MallBaseId: MallBaseId,
TenantId: TenantId,
EmpId: EmpId,
ERPGroupId: ERPGroupId,
ERPEmpId: ERPEmpId,
ERPBranchId: ERPBranchId,
// MiniAppId:"wxacd9f8cc3480d29e",
// OpenId:"ow_7I5ZQKhAB66yvOTGI35Xk-Kmg",
// UserId:19992,
}
return postData
},
//文件下载
Vue.prototype.GetLocalFile = function (cmd, msg, fileName, newCmd, successCall) {
var apiurl = this.domainManager().DomainUrl + cmd;
var postData = this.GetPostData(cmd, msg, newCmd);
this.$http.post(apiurl, postData, {
responseType: 'arraybuffer'
}).then((res) => {
let blob = new Blob([res.data], {
type: "application/vnd.ms-excel"
})
let url = URL.createObjectURL(blob);
let link = document.createElement('a');
link.href = url;
link.setAttribute("download", fileName);
document.body.appendChild(link);
link.click();
successCall(res);
}).catch(function (res) {});
},
//文件下载
Vue.prototype.GetLocalFile = function(cmd, msg, fileName, newCmd, successCall) {
var apiurl = this.domainManager().DomainUrl + cmd;
var postData = this.GetPostData(cmd, msg, newCmd);
this.$http.post(apiurl, postData, {
responseType: 'arraybuffer'
}).then((res) => {
let blob = new Blob([res.data], {
type: "application/vnd.ms-excel"
})
let url = URL.createObjectURL(blob);
let link = document.createElement('a');
link.href = url;
link.setAttribute("download", fileName);
document.body.appendChild(link);
link.click();
successCall(res);
}).catch(function(res) {});
},
//调用资产的接口
Vue.prototype.apiJavaPost = function (cmd, msg, successCall, faildCall) {
if (msg == null || msg == "") {
msg = {}
}
var apiurl = this.domainManager().javaUrl + cmd;
var timestamp = (new Date()).valueOf();
this.apiurl = apiurl;
var token = "";
var key = "";
var MallBaseId = "0"; //小程序ID
var TenantId = "0"; //商户Id
var uid = "0"
if (this.getLocalStorage() != null) {
token = this.getLocalStorage().Token;
key = this.getLocalStorage().SecretKey;
MallBaseId = this.getLocalStorage().MallBaseId;
TenantId = this.getLocalStorage().TenantId;
uid = this.getLocalStorage().ERPEmpId
}
var md5Str = md5(`msg=YXZCGL2020&timestamp=${timestamp}&token=${token}&key=${key}`);
var postData = {
"msg": msg,
"timestamp": timestamp,
"token": token,
"sign": md5Str,
"MallBaseId": MallBaseId,
"TenantId": TenantId,
'uid': uid
}
if (localStorage.g && localStorage.g != 'undefined') {
postData.groupId = 2;
}
this.$http.post(apiurl, postData, {
headers: {
'Content-Type': 'application/json',
'Referer-Viitto': this.$route.path
}
})
.then(res => {
if (res.data.resultCode == 10000 || res.data.resultCode == 10001) {
this.$router.push({
path: '/login'
})
} else if (res.data.resultCode == 10005) {
this.$router.go(-1)
} else {
successCall(res)
//调用资产的接口
Vue.prototype.apiJavaPost = function(cmd, msg, successCall, faildCall) {
if (msg == null || msg == "") {
msg = {}
}
var apiurl = this.domainManager().javaUrl + cmd;
var timestamp = (new Date()).valueOf();
this.apiurl = apiurl;
var token = "";
var key = "";
var MallBaseId = "0"; //小程序ID
var TenantId = "0"; //商户Id
var uid = "0"
if (this.getLocalStorage() != null) {
token = this.getLocalStorage().Token;
key = this.getLocalStorage().SecretKey;
MallBaseId = this.getLocalStorage().MallBaseId;
TenantId = this.getLocalStorage().TenantId;
uid = this.getLocalStorage().ERPEmpId
}
var md5Str = md5(`msg=YXZCGL2020&timestamp=${timestamp}&token=${token}&key=${key}`);
var postData = {
"msg": msg,
"timestamp": timestamp,
"token": token,
"sign": md5Str,
"MallBaseId": MallBaseId,
"TenantId": TenantId,
'uid': uid
}
if (localStorage.g && localStorage.g != 'undefined') {
postData.groupId = 2;
}
this.$http.post(apiurl, postData, {
headers: {
'Content-Type': 'application/json',
'Referer-Viitto': this.$route.path
}
})
.then(res => {
if (res.data.resultCode == 10000 || res.data.resultCode == 10001) {
this.$router.push({
path: '/login'
})
} else if (res.data.resultCode == 10005) {
this.$router.go(-1)
} else {
successCall(res)
}
}, faildCall)
}
}, faildCall)
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment