Authored by htoooth

import

... ... @@ -7,6 +7,7 @@
<script>
import request from 'axios';
import _ from 'lodash';
export default {
name: 'XlsxUpload',
... ... @@ -40,6 +41,12 @@
default() {
return {};
}
},
data: {
type: Object,
default() {
return {};
}
}
},
data() {
... ... @@ -55,7 +62,7 @@
this.files = e.target.files;
this.onChange(this.files);
},
upload() {
upload(data) {
let files = this.files;
let postFiles = Array.prototype.slice.call(files);
... ... @@ -65,12 +72,14 @@
return;
}
return this.post(postFiles[0]);
Object.assign(this.data, data);
return this.post(postFiles[0], this.data);
},
clear() {
this.files = null;
},
post(file) {
post(file, params) {
let _this = this;
let config = {
onUploadProgress(processEvent) {
... ... @@ -81,6 +90,12 @@
data.append('file', file);
if (!_.isEmpty(params)) {
_.each(params, (v, k) => {
data.append(k, v);
});
}
return request.post(this.action, data, config)
.then((result) => {
_this.onSuccess(result.data);
... ...
... ... @@ -27,8 +27,14 @@
<Option v-for="item in operator.list" :value="item.id" :key="item">{{ item.label }}</Option>
</Select>
</FilterItem>
<FilterItem label="品牌">
<SelectBrand v-model="brandId"></SelectBrand>
</FilterItem>
<FilterItem label="上传文件">
<Input v-model="xlsxFile" style="width: 300px"></Input>
<XlsxUpload
ref="xlsxUpload"
:action="action"
... ... @@ -40,6 +46,7 @@
</XlsxUpload>
</FilterItem>
<FilterItem>
<Button type="primary" @click="upload">开始上传</Button>
</FilterItem>
... ... @@ -48,7 +55,7 @@
</template>
<script>
import {SelectCategory} from 'components/select';
import {SelectCategory, SelectBrand} from 'components/select';
export default {
data() {
... ... @@ -72,7 +79,8 @@
]
},
xlsxFile: '',
action: '',
brandId: '',
action: '/importSeller',
sort: {
first: {
label: '选择类目',
... ... @@ -121,7 +129,7 @@
this.xlsxFile = files[0].name;
},
upload() {
this.$refs.xlsxUpload.upload();
this.$refs.xlsxUpload.upload({brandId: this.brandId});
},
onSuccess(data) {
... ... @@ -134,7 +142,8 @@
}
},
components: {
SelectCategory
SelectCategory,
SelectBrand
}
};
</script>
... ...
... ... @@ -64,7 +64,8 @@ let domainApis = {
getBindProduct: '/SellerShopController/getBindProduct',
addCategoryLinkProduct: '/SellerShopController/addCategoryLinkProduct',
deleteCategoryLinkProduct: '/SellerShopController/deleteCategoryLinkProduct',
getRemoteImageUrlBySku: '/product/getRemoteImageUrlBySku'
getRemoteImageUrlBySku: '/product/getRemoteImageUrlBySku',
importSeller: '/batch/importSeller'
},
shop: {
login: '/loginInter',
... ...
... ... @@ -95,6 +95,20 @@ class FileController extends Context {
next();
}).catch(next);
}
importSeller(req, res, next) {
let file = req.files && req.files.file;
this.api.upload(apiDomain.platform.importSeller, {
brandId: req.body.brandId,
shopsId: req.cookies._sign,
userId: req.session.LOGIN_UID,
file: fs.createReadStream(file.path),
type: 'sellerProductImport'
}).then((result) => {
res.json(result);
}).catch(next);
}
}
module.exports = FileController;
... ...
... ... @@ -22,5 +22,6 @@ router.post('/logout', middleware(UserController, 'logout'));
router.post('/switchShop', before, auth, middleware(UserController, 'switchShop'));
router.post('/upload/image', before, auth, multipartMiddleware, middleware(FileController, 'uploadImage'));
router.post('/upload/xlsx', before, auth, multipartMiddleware, middleware(FileController, 'uploadXlsx'));
router.post('/importSeller', before, auth, multipartMiddleware, middleware(FileController, 'importSeller'));
module.exports = router;
... ...