提交 966835ac authored 作者: lihuihui's avatar lihuihui
...@@ -15,12 +15,6 @@ module.exports = { ...@@ -15,12 +15,6 @@ module.exports = {
} }
}, },
ProvidePlugin: { ProvidePlugin: {
CKEDITOR: 'window.CKEDITOR',
VideoJs: 'window.swfobject',
Base64: 'window.Base64',
Md5: 'window.md5',
$: 'window.$',
Aliplayer: 'window.Aliplayer',
AliPlayerComponent: 'window.AliPlayerComponent'
} }
} }
...@@ -15,12 +15,6 @@ module.exports = { ...@@ -15,12 +15,6 @@ module.exports = {
} }
}, },
ProvidePlugin: { ProvidePlugin: {
CKEDITOR: 'window.CKEDITOR',
VideoJs: 'window.swfobject',
Base64: 'window.Base64',
Md5: 'window.md5',
$: 'window.$',
Aliplayer: 'window.Aliplayer',
AliPlayerComponent: 'window.AliPlayerComponent'
} }
} }
...@@ -16,12 +16,6 @@ module.exports = { ...@@ -16,12 +16,6 @@ module.exports = {
} }
}, },
ProvidePlugin: { ProvidePlugin: {
CKEDITOR: 'window.CKEDITOR',
VideoJs: 'window.swfobject',
Base64: 'window.Base64',
Md5: 'window.md5',
$: 'window.$',
Aliplayer: 'window.Aliplayer',
AliPlayerComponent: 'window.AliPlayerComponent'
} }
} }
/**
* 本文件执行,需要 node -v >= v8.11.3
* 原因:其中使用很多es6新特性,需要高版本才能直接识别并运行
* 放服务器上 上传慢,而且经常报错(没找到原因),最后改为打包完成后自动上传不在服务器上deploy时再上传了
*/
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
// 这个包本身也是用es6语法写的,低版本node编译解析不了
const OSS = require('ali-oss') const OSS = require('ali-oss')
const conf = require('./config') const conf = require('./config')
...@@ -13,53 +18,64 @@ const client = new OSS({ ...@@ -13,53 +18,64 @@ const client = new OSS({
bucket: 'zws-imgs-pub' bucket: 'zws-imgs-pub'
}) })
let DIR_PATH = path.join(__dirname, '../' + conf.DesDir) /* 定位到对应 public目录下 */
let PREFIX_PATH = conf.CDN_DIR const DIR_PATH = path.join(__dirname, '../' + conf.DesDir)
/* 上传对应目录 */
const PREFIX_PATH = conf.CDN_DIR
/* 是否上传static目录 */
const isUploadStatic = conf.isUploadStatic
let count = 1 let fileCount = 1
/**
* 调用接口,单个文件上传
* @param {string} dirPath 传入对应需要遍历的路径
* @param {function} callback 加入一个回调方法,执行文件上传
*/
async function uploadFile (prefixPath, dirFileName) { async function uploadFile (prefixPath, dirFileName) {
try { try {
const upFilePath = prefixPath.replace(new RegExp(DIR_PATH, 'gi'), '') + path.basename(dirFileName)
let result = await client.put(prefixPath + path.basename(dirFileName), dirFileName) let result = await client.put(prefixPath + path.basename(dirFileName), dirFileName)
if (result.res.status === 200) { if (result.res.status === 200) {
console.log('第' + (count++) + '个文件:' + path.basename(dirFileName) + ',已上传。') console.log('第' + fileCount++ + '个文件,已上传:' + conf.CDN_BASE + upFilePath)
return { status: 200 }
} }
} catch (err) { } catch (err) {
console.log(err) console.log('第' + fileCount++ + '个文件,上传失败:' + conf.CDN_BASE + upFilePath)
let text = await function () { return 1 } return { status: 500, err: err }
console.log(text)
} }
} }
function findfiles (dirPath, callback) { /**
fs.readdir(dirPath, function (err, files) { * 循环遍历文件,准备上传文件
if (err) { * 原生js 遍历方法
console.log(err) * @param {string} dirPath 传入对应需要遍历的路径
} else { * @param {function} callback 加入一个回调方法,执行文件上传
files.forEach(function (filename) { */
var filedir = path.join(dirPath, filename) function uploadfiles (dirPath, callback) {
fs.stat(filedir, function (error, stats) { /* 根据文件路径读取文件 */
if (error) { const files = fs.readdirSync(dirPath)
console.log('获取文件stats失败') files.forEach(function (filename, i) {
} else { const filedir = path.join(dirPath, filename)
var isFile = stats.isFile() const info = fs.statSync(filedir)
var isDir = stats.isDirectory() if (info.isDirectory()) {
if (isFile && typeof callback === 'function') { /* 确定是否上传 */
callback(filedir) if (!(isUploadStatic ? true : filename !== 'static')) { return }
} /* 得到对应目录结构 */
if (isDir && (conf.isUploadStatic ? true : filename !== 'static')) { const morePath = filedir.replace(new RegExp(DIR_PATH, 'gi'), '') + '/'
var morePath = filedir.replace(new RegExp(DIR_PATH + '/', 'g'), '') + '/' /* 递归,如果是文件夹,就继续遍历该文件夹下面的文件 */
findfiles(filedir, function (filedir) { uploadfiles(filedir, function (filedir) {
uploadFile(PREFIX_PATH + morePath, filedir) uploadFile(path.join(PREFIX_PATH, morePath), filedir)
})
}
}
})
}) })
} else {
if (typeof callback === 'function') {
callback(filedir)
} else {
uploadFile(PREFIX_PATH, filedir)
}
} }
}) })
return true
} }
findfiles(DIR_PATH, function (filedir) { /* 批量上传文件 */
uploadFile(PREFIX_PATH, filedir) uploadfiles(DIR_PATH, null)
})
...@@ -66,6 +66,17 @@ export default class API { ...@@ -66,6 +66,17 @@ export default class API {
.then(beforeSuccess.bind(this), beforeFail.bind(this)) .then(beforeSuccess.bind(this), beforeFail.bind(this))
} }
setConfirm (titleStr, btnStr, msgStr) {
return MessageBox.confirm(msgStr, titleStr, {
confirmButtonText: btnStr,
type: 'warning',
showClose: false,
closeOnPressEscape: false,
closeOnClickModal: false,
showCancelButton: false
})
}
/** /**
* 统一处理request success操作,在实现业务逻辑前进行统一处理。 * 统一处理request success操作,在实现业务逻辑前进行统一处理。
* 注意:如果不能满足需求,可在接口定义处重新实现 * 注意:如果不能满足需求,可在接口定义处重新实现
...@@ -79,10 +90,7 @@ export default class API { ...@@ -79,10 +90,7 @@ export default class API {
if (data && data.code !== undefined) { if (data && data.code !== undefined) {
if (data.code !== 0) { if (data.code !== 0) {
if (!/account\/get-user-info/gi.test(res.config.url)) { if (!/account\/get-user-info/gi.test(res.config.url)) {
Message({ Message({ type: 'error', message: data.msg })
type: 'error',
message: data.msg
})
} }
return null return null
} else if (data.code === 0) { } else if (data.code === 0) {
...@@ -92,21 +100,11 @@ export default class API { ...@@ -92,21 +100,11 @@ export default class API {
return data return data
} else if (status === 403 && !/\/getinfo$/gi.test(res.config.url)) { } else if (status === 403 && !/\/getinfo$/gi.test(res.config.url)) {
/* 不带 code 参数,老接口模型 */ /* 不带 code 参数,老接口模型 */
MessageBox.confirm('登录状态已过期, 请重新登录。', '提示', { this.setConfirm('提示', '确定', '登录状态已过期, 请重新登录。').then(() => {
confirmButtonText: '确定',
type: 'warning',
showClose: false,
closeOnPressEscape: false,
closeOnClickModal: false,
showCancelButton: false
}).then(() => {
/* 重新刷新当前页 */ /* 重新刷新当前页 */
window.location.reload() window.location.reload()
}).catch(() => { }).catch(() => {
Message({ Message({ type: 'info', message: '操作已取消,将不再记录任何数据操作,除非重新登录' })
type: 'info',
message: '操作已取消,将不再记录任何数据操作,除非重新登录'
})
}) })
} else if (status !== 200 && data.message) { } else if (status !== 200 && data.message) {
throw new Error(data.message) throw new Error(data.message)
...@@ -121,12 +119,27 @@ export default class API { ...@@ -121,12 +119,27 @@ export default class API {
* @param {[object]} res 如果未到达 response 阶段,则无res.response * @param {[object]} res 如果未到达 response 阶段,则无res.response
*/ */
_reqFail (res) { _reqFail (res) {
debugger
let err = null let err = null
if (res.code === 'ECONNABORTED') { if (res.code === 'ECONNABORTED') {
err = new Error('网络超时,请稍后重试') err = new Error('网络超时,请稍后重试')
} else if (res.response) { } else if (res.response) {
err = new Error(JSON.stringify(res.response)) /* 不带 code 参数,老接口模型 */
if (res.response.data) {
if (!/\/getinfo$/gi.test(res.config.url) && res.response.data.status === 403) {
this.setConfirm('提示', '确定', '登录状态已过期, 请重新登录。').then(() => {
/* 重新刷新当前页 */
window.location.reload()
}).catch(() => {
Message({ type: 'info', message: '已取消,将不再记录任何数据操作,除非重新登录' })
})
}
} else if (res.response.data.status === 401 && res.response.data.message) {
this.setConfirm('提示', '关闭', res.response.data.message).then(() => {
/* 重新刷新当前页 */
window.location.reload()
})
}
err = new Error(JSON.stringify(res.response.data))
} else { } else {
err = new Error('msg:' + res.message + 'stack:' + res.stack) err = new Error('msg:' + res.message + 'stack:' + res.stack)
err.code = 500 err.code = 500
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论