Authored by 陈峰

api

... ... @@ -9,6 +9,7 @@ import './filters';
import './directives';
import 'iview/dist/styles/iview.css';
import 'common.scss';
import 'font-awesome/css/font-awesome.css';
let router = new Router({routes: Routers});
... ...
// 懒加载VueHtml5Editor
import _ from 'lodash';
const component = function editor(resolve) {
require.ensure([], () => {
const VueHtml5Editor = require('vue-html5-editor');
const editorInstance = new VueHtml5Editor({
hiddenModules: ['info'],
image: {
sizeLimit: 512 * 1024,
upload: {
url: '/upload/image',
headers: {},
params: {
bucket: 'goodsimg'
},
fieldName: 'file'
},
compress: null,
uploadHandler(responseText) {
let json = JSON.parse(responseText);
if (json.code === 200) {
return _.get(json, 'data.imagesList[0]', '');
}
return json.data;
}
},
language: 'zh-cn',
modules: {}
});
resolve(editorInstance);
}, 'editor');
};
export default component;
... ...
import menus from './menus';
import breadcrumb from './breadcrumb';
import userInfo from './user-info';
// import quillEditor from './quill-editor';
import editor from './editor';
import yohoUpload from './yoho-upload';
export default [menus, breadcrumb, userInfo];
export default {
menus,
breadcrumb,
userInfo,
editor,
yohoUpload
};
... ...
// 懒加载vue-quill-editor
const component = function quillEditor(r) {
require.ensure([], () => r(require('vue-quill-editor').quillEditor), 'editor');
};
export default component;
<template>
<Upload ref="upload"
:id="id"
:action="action"
:data="data"
:accept="accept"
:maxSize="maxSize"
:on-success="success"
:on-error="error"
:before-upload="beforeUpload">
<Button type="ghost" icon="ios-cloud-upload-outline">上传文件</Button>
</Upload>
</template>
<script>
import _ from 'lodash';
export default {
name: 'yoho-upload',
props: {
action: {
type: String,
default: '/upload/image'
},
data: {
type: Object,
default: () => {
return {
bucket: 'goodsimg'
};
}
},
accept: {
type: String,
default: 'image/png,image/jpeg,image/gif,image/jpg'
},
maxSize: {
type: Number,
default: 512 * 1024
},
id: ''
},
data() {
return {};
},
methods: {
success(response) {
let files = [];
if (_.get(response, 'data.imagesList.length', 0)) {
files = response.data.imagesList;
}
this.$emit('on-success', this.id, files);
},
error(error) {
this.$Message.error('上传失败');
this.$emit('on-error', this.id, error);
},
beforeUpload() {
this.$refs.upload.clearFiles();
return true;
}
}
};
</script>
... ...
import SizeEdit from './size-edit';
export {
SizeEdit
};
... ...
<template>
<Modal :visible="show"></Modal>
</template>
<script>
export default {
name: 'size-edit',
props: {
show: {
type: Boolean,
default: false
}
},
data() {
return {
};
},
};
</script>
<style lang="scss" scoped>
</style>
... ...
<template>
<div>
overview
<quill-editor v-model="content"
ref="myQuillEditor">
</quill-editor>
<Table ref="table" :data="data" :columns="columns"></Table>
<Button @click="getTable">获得数据</Button>
<Button @click="addRow">增加一列</Button>
{{data}}
<br />
<editor :content="content" @change="updateData"></editor>
{{content}}
<yoho-upload id="123" @on-success="uploadSuccess" @on-error="uploadError"></yoho-upload>
</div>
</template>
... ... @@ -14,13 +20,32 @@ export default {
data() {
return {
content: '',
editorOption: {
}
columns: [
{title: '列', key: 'name', render(row, col, index) {
return `<input type="text" v-model="row.name" />`;
}}
],
data: [
{name: '1'}
]
};
},
computed: {
editor() {
return this.$refs.myQuillEditor.quill;
methods: {
getTable() {
console.log(this.$refs.table.rebuildData);
},
addRow() {
this.data = this.$refs.table.rebuildData;
this.data.push({name: '2'})
},
updateData(c) {
this.content = c;
},
uploadSuccess(id, files) {
console.log(id, files)
},
uploadError(id, error) {
console.log(id, error)
}
}
};
... ...
... ... @@ -3,22 +3,20 @@ let apiUrl = {
brand: '/platform/getSellerBrandInfo',
sort: '/platform/getSellerSortInfo',
color: '/platform/querySellerProductColors',
size: '/platform/querySortSize'
size: '/platform/querySortSize',
material: '/platform/querySellerProductMaterial',
wash: '/platform/querySellerProductWashTips',
addProduct: '/platform/addProduct'
};
const request = require('axios');
function getBrand(shopId) {
return request.get(apiUrl.brand, {
params: {
shopsId:shopId
}
}).then((result) => result.data)
function getBrand() {
return request.get(apiUrl.brand).then((result) => result.data);
}
function getSort(shopId, brandId, level , sortId) {
function getSort(brandId, level, sortId) {
let opts = {
shopsId: shopId,
brandId: brandId,
level: level
};
... ... @@ -33,7 +31,7 @@ function getSort(shopId, brandId, level , sortId) {
}
function getColor() {
return request.get(apiUrl.color).then((result) => result.data)
return request.get(apiUrl.color).then((result) => result.data);
}
function getSize(smallSortId) {
... ... @@ -41,12 +39,51 @@ function getSize(smallSortId) {
params: {
sortId: smallSortId
}
}).then(result => result.data)
}).then(result => result.data);
}
/**
* 材质类型
* @param {string} sortId
*/
function getMaterial(sortId) {
return require.get(apiUrl.material, {
params: {
maxSortId: sortId
}
}).then(result => result.data);
}
/**
* 透气性
* @param {*} sortId
*/
function getPorousAbility(sortId) {
}
/**
* 洗涤提示
* @param {*} sorId
*/
function getWashTip(sorId) {
return request.get(apiUrl.wash, {
});
}
function saveBaseProductInfo(product) {
return request.post(apiUrl.addProduct, {
params: product
}).then(result => result.data);
}
export default {
getBrand,
getSort,
getColor,
getSize
}
getSize,
getMaterial,
getPorousAbility,
getWashTip,
saveBaseProductInfo
};
... ...
... ... @@ -29,6 +29,39 @@
}
</script>
<style lang="scss" scoped>
<style lang="scss">
.create-group {
font-size: 18px;
font-weight: bold;
line-height: 40px;
margin-top: 10px;
margin-bottom: 10px;
}
.create-group-indicator {
display: inline-block;
border: 3px solid black;
height: 20px;
vertical-align: text-top;
}
.create-group-title {
}
.create-group-sub-title {
color: #CC9900;
}
.create-item-title {
font-size: 15px;
font-weight: bold;
background-color: #FAFAFA;
height: 40px;
line-height: 40px;
margin-bottom: 20px;
}
</style>
... ...
... ... @@ -4,7 +4,6 @@
export default () => {
return {
shopId: '',
brandId: '',
brandName: '',
maxSortId: '',
... ... @@ -18,8 +17,10 @@ export default () => {
goodsSeason: '',
gender: '',
seasons: '',
expectSaleTimeStr: '',
ageLevel: [],
retailPrice: '',
salesPrice: ''
salesPrice: '',
sellerGoodsInfoStr: ''
};
}
\ No newline at end of file
... ...
<template>
<div>
<Row>
<div class="create-group">
<span class="create-group-indicator"></span>
<span class="create-group-title">类目选择</span>
<span class="create-group-sub-title">(指定商品的类目)</span>
</div>
</Row>
<Row>
<Col span="8">
<Form :model="product" :label-width="80">
<Form :model="product" :label-width="70">
<Form-item label="品 牌*">
<Select v-model="product.brandId" placeholder="请选择" :label-in-value="true" @on-change="selectBrand">
<Option v-for="brand in brands" :value="brand.brandId" :key="brand">{{ brand.brandName }}</Option>
... ... @@ -14,7 +22,7 @@
<Row>
<Col span="8" v-if="show[1]">
<Form :model="product" :label-width="80">
<Form :model="product" :label-width="70">
<Form-item label="类目*">
<Select v-model="pickedSortId[1]" placeholder="一级类目" @on-change="selectSort1" :label-in-value="true">
<Option v-for="sort in sorts[1]" :value="sort.sortId" :key="sort">{{ sort.sortName }}</Option>
... ... @@ -23,7 +31,7 @@
</Form>
</Col>
<Col span="8" v-if="show[2]">
<Col span="6" offset="1" v-if="show[2]">
<Form :model="product">
<Form-item>
<Select v-model="pickedSortId[2]" placeholder="二级类目" @on-change="selectSort2" :label-in-value="true">
... ... @@ -33,7 +41,7 @@
</Form>
</Col>
<Col span="8" v-if="show[3]">
<Col span="6" offset="1" v-if="show[3]">
<Form :model="product">
<Form-item>
<Select v-model="pickedSortId[3]" placeholder="三级类目" @on-change="selectSort3" :label-in-value="true">
... ... @@ -43,10 +51,14 @@
</Form>
</Col>
</Row>
<span>{{this.sortName}}</span>
<div>
<Button type="primary" @click="nextStep">下一步</Button>
</div>
<Row>
<Col span="2" offset="12">
<div>
<Button type="primary" @click="nextStep">下一步</Button>
</div>
</Col>
</Row>
</div>
</template>
... ... @@ -56,7 +68,6 @@
export default {
props: ['step', 'product'],
mounted : function() {
// this.shopId = this.$cookie.get('SHOP_ID');
this.getBrand();
},
data() {
... ... @@ -114,11 +125,10 @@
this.product.smallSortId = this.sortId;
},
selectBrand: function(value) {
console.log(value);
this.product.brandName = value.label;
},
getBrand: function() {
return api.getBrand(this.shopId).then((result) => {
return api.getBrand().then((result) => {
if (result.code === 200) {
this.brands = result.data;
}
... ... @@ -126,7 +136,6 @@
},
getSort: function() {
return api.getSort(
this.shopId,
this.product.brandId,
this.level,
this.sortId
... ... @@ -138,17 +147,16 @@
});
}
},
computed: {
sortName: function() {
return this.product.sortName = `${this.pickedLabel[1]}/${this.pickedLabel[2]}/${this.pickedLabel[3]}`
}
},
watch: {
'product.brandId': function() {
this.level = 1;
this.sortId = '';
this.getSort();
},
'pickedLabel.3': function() {
this.product.sortName = `${this.pickedLabel[1]}/${this.pickedLabel[2]}/${this.pickedLabel[3]}`
}
}
}
</script>
... ...
<template>
<div>
<Form :model="product" :label-width="80">
<Row>
<Col span="8">
<Form-item>
<span>商品基本信息</span>
</Form-item>
<Form :model="product" :label-width="70">
<Row>
<div class="create-group">
<span class="create-group-indicator"></span>
<span class="create-group-title">基础信息</span>
<span class="create-group-sub-title">(该信息必须项编缉完成后可以保存, 可以将商品发货入仓)</span>
</div>
</Row>
<Row>
<Col>
<div class="create-item-title">商品基本信息</div>
</Col>
</Row>
<Row>
<Col span="8">
<Form-item label="品 牌*">
<Form-item label="品牌*">
<span>{{product.brandName}}</span>
</Form-item>
</Col>
... ... @@ -52,7 +59,8 @@
<Row>
<Col span="8">
<Form-item label="货品年*">
<Date-picker type="year" placeholder="选择年" style="width: 200px"></Date-picker>
<Date-picker :value="product.goodsYears" @on-change="clickGoodsYear" type="year" placeholder="选择年" style="width: 200px">
</Date-picker>
</Form-item>
</Col>
</Row>
... ... @@ -75,7 +83,7 @@
<Row>
<Col span="8">
<Form-item label="上市日期*">
<Date-picker type="date" placeholder="选择日期" style="width: 200px"></Date-picker>
<Date-picker :value="product.expectSaleTimeStr" @on-change="clickSaleDate" type="date" placeholder="选择日期" style="width: 200px"></Date-picker>
</Form-item>
</Col>
</Row>
... ... @@ -113,7 +121,7 @@
<Form-item label="年龄层*">
<Checkbox-group v-model="product.ageLevel">
<Checkbox-group v-model="ageLevel">
<Checkbox label="1">
<span>成人</span>
</Checkbox>
... ... @@ -133,15 +141,20 @@
</Form-item>
<Row>
<Col span="8">
<span>商品规格</span>
<Col>
<div class="create-item-title">商品规格
<span class="create-group-sub-title">(颜色名称只能填写中文,最多5个汉字。款型编码和条码只能填写英文和数字,不区分大小写)</span>
</div>
</Col>
</Row>
<Row>
<Form-item label="颜色*">
<span class='squre' v-for="color in colors" @click="clickColor(color)">
<span class="squre-color" :style="{ 'background-color': '#' + color.colorCode}"></span>
<span class="squre-color"
:style="{ 'background-color': '#' + color.colorCode}"
:class="{ 'squre-color-selected': color.selected}">
</span>
<span class="squre-name">{{color.colorName}}</span>
</span>
</Form-item>
... ... @@ -164,10 +177,8 @@
</Row>
<Row>
<Col span="8">
<Form-item>
<span>商品价格</span>
</Form-item>
<Col>
<div class="create-item-title">商品价格</div>
</Col>
</Row>
... ... @@ -190,10 +201,12 @@
</Form>
<div>
<Button type="primary" @click="backStep">上一步</Button>
<Button type="primary" @click="nextStep">下一步</Button>
</div>
<Row>
<Col span="6" offset="10" class="text-center">
<Button type="primary" @click="backStep">上一步</Button>
<Button type="primary" @click="nextStep">下一步</Button>
</Col>
</Row>
</div>
</template>
... ... @@ -202,6 +215,18 @@
import api from '../api';
const _ = require('lodash');
const makeColor = () => {
return {
factoryCode: '',
factoryGoodsName: '',
goodsColorImage: '',
goodsName: '',
colorId: '',
isDefault: 'Y',
goodsSizeList: []
};
};
export default {
props: ['step', 'product'],
data() {
... ... @@ -226,7 +251,14 @@
title: '颜色展示名称*',
key: 'factoryGoodsName',
render(row, col, index) {
return `<i-input placeholder="请输入..." style="width: 50px"></i-input>`
return `<div v-if="isExist(${index})">
<i-input
:value="table.data[${index}].factoryGoodsName"
placeholder="请输入..."
style="width: 100px"
@on-change="changeFactoryGoodsName($event,${index})">
</i-input>
</div>`
}
},
{
... ... @@ -242,7 +274,9 @@
title: '款型编码',
key: 'factoryCode',
render(row, col, index) {
return `<i-input placeholder="请输入..." style="width: 50px"></i-input>`
return `<div v-if="isExist(${index})">
<i-input :value="table.data[${index}].factoryCode" placeholder="请输入..." style="width: 100px"></i-input>
</div>`
}
},
{
... ... @@ -261,8 +295,8 @@
key: 'sizeCode',
render(row, col, index) {
return `<div class='size-code'>
<div v-for="size in row.sizeCode" class="row-span">
<i-input placeholder="请输入..." style="width: 50px"/>
<div v-for="size,i in row.sizeCode" class="row-span">
<i-input :value="table.data[${index}].sizeCode.name" placeholder="请输入..." style="width: 100px"/>
</div>
</div>`;
}
... ... @@ -285,7 +319,8 @@
data: [],
selectedSizes: [],
selectedColors: []
}
},
ageLevel: [],
}
},
mounted: function() {
... ... @@ -294,12 +329,11 @@
},
methods: {
nextStep: function() {
console.log(this.product);
console.log(this.table);
this.step.value = 2;
this.$router.push({name:'product.create.step3'})
},
nextStep: function() {
this.step.value = 2;
this.$router.push({name:'product.create.step3'})
// this.$router.push({name:'product.create.step3'})
},
backStep: function() {
this.step.value = 0;
... ... @@ -313,7 +347,8 @@
});
},
getSize: function() {
return api.getSize(119).then((result) => {
// return api.getSize(this.product.smallSortId).then((result) => {
return api.getSize(129).then((result) => {
if(result.code === 200) {
this.sizes = result.data;
}
... ... @@ -322,6 +357,10 @@
clickColor: function(color) {
this.addColor(color);
},
changeFactoryGoodsName: function(event, index) {
console.log(event.target.value);
this.table.data[index].factoryGoodsName = event.target.value;
},
clickDefault: function(index) {
let color = this.table.data[index];
... ... @@ -330,16 +369,22 @@
if(c.colorId !== color.colorId) {
c.goodsName.isDefault = false;
}
})
});
},
clickOperator: function(rowIndex, itemIndex) {
let rowColor = this.table.data[rowIndex];
rowColor.operator[itemIndex].value = rowColor.operator[itemIndex].value ? false:true;
},
clickGoodsYear: function(value) {
this.product.goodsYears = value;
},
clickSaleDate: function(value) {
this.product.expectSaleTimeStr = value
},
initDefault: function() {
let init = _.some(this.table.data, (c) => {
return c.goodsName.isDefault
})
});
if (init) {
return;
... ... @@ -354,14 +399,16 @@
addColor: function(color) {
let findColorIndex = this.table.selectedColors.findIndex((c) => {
return c.id === color.id;
})
});
if (findColorIndex !== -1) {
this.removeColorData(color);
this.table.selectedColors.splice(findColorIndex, 1)
this.table.selectedColors.splice(findColorIndex, 1);
color.selected = false;
} else {
this.addColorData(color);
this.table.selectedColors.push(color)
this.table.selectedColors.push(color);
color.selected = true;
}
this.initDefault();
... ... @@ -389,8 +436,7 @@
removeSize: function(color, sizeId) {
let index = color.sizeId.findIndex((s) => {
return s.id === sizeId;
})
});
if (index !== -1) {
color.sizeId.splice(index, 1);
... ... @@ -411,12 +457,12 @@
sizeId: [],
sizeCode: [],
operator: []
}
};
if (this.table.selectedSizes.length > 0) {
this.table.selectedSizes.forEach((sizeId) => {
this.addSize(newColor, sizeId)
})
});
}
this.table.data.push(newColor);
... ... @@ -465,6 +511,16 @@
}
return false;
},
submit: function() {
api.saveBaseProductInfo(this.product).then((result) => {
if (result.code === 200) {
console.log(result.data);
}
});
},
beforeSubmit: function() {
}
},
watch: {
... ... @@ -486,6 +542,9 @@
this.removeSize(color, removeSize[0]);
}
})
},
'ageLevel': function() {
this.product.ageLevel = this.ageLevel.join('|');
}
}
}
... ... @@ -522,7 +581,10 @@
display: inline-block;
height: 30px;
width: 30px;
border: 1px solid gainsboro;
}
.squre-color-selected {
border: 2px solid black;
}
.squre-name {
... ...
... ... @@ -19,7 +19,7 @@
</Row>
<Row>
</Row>
<Row>
... ...
... ... @@ -100,6 +100,7 @@
<div class="list-page">
<Page :total="pageData.total" @on-change="pageChange" :page-size="20" show-total></Page>
</div>
<size-edit></size-edit>
</div>
</template>
... ... @@ -107,6 +108,7 @@
import _ from 'lodash';
import service from 'product-service';
import {Brand, Category} from 'product/filter-select';
import {SizeEdit} from 'product/size-edit';
import {filterFields, tableCols, tableData, pageData} from './store';
export default {
... ... @@ -233,7 +235,8 @@
},
components: {
Brand,
Category
Category,
SizeEdit
}
}
</script>
... ...
... ... @@ -7,6 +7,7 @@ import store from 'yoho-store';
import components from '../components/common';
import axios from 'axios';
import config from 'config';
import _ from 'lodash';
const plugin = {
install(Vue, options) {
... ... @@ -32,7 +33,7 @@ const plugin = {
// 加载核心组件
components.forEach(component => {
_.each(components, component => {
Vue.component(component.name, component);
});
... ...
... ... @@ -4,6 +4,7 @@
import _ from 'lodash';
import axios from 'axios';
import purviews from 'purview';
import Message from 'iview/src/components/message';
const plugin = {
install(Vue) {
... ... @@ -37,7 +38,7 @@ const plugin = {
Vue.logout();
return false;
}
Vue.$Message.error('接口异常');
Message.error('接口异常');
return false;
};
}
... ...
... ... @@ -18,10 +18,12 @@
"bluebird": "^3.5.0",
"body-parser": "^1.17.1",
"compression": "^1.6.2",
"connect-multiparty": "^2.0.0",
"cookie-parser": "^1.4.3",
"cookie-session": "^2.0.0-beta.1",
"express": "^4.15.2",
"express-session": "^1.15.2",
"font-awesome": "^4.7.0",
"iview": "^2.0.0-rc.8",
"lodash": "^4.17.4",
"moment": "^2.18.1",
... ... @@ -31,7 +33,7 @@
"uuid": "^3.0.1",
"vue": "^2.2.2",
"vue-cookie": "^1.1.4",
"vue-quill-editor": "^2.1.2",
"vue-html5-editor": "^1.1.1",
"vue-router": "^2.2.0",
"vue-template-compiler": "^2.2.6",
"webpack-dev-server": "^2.4.2",
... ...
... ... @@ -13,7 +13,9 @@ let domainApis = {
querySortSize: '/SellerSortSizeController/querySortSize',
querySellerProductList: '/SellerProductController/querySellerProductList',
productOutSale: '/SellerSknStatusController/productOutSale',
updateSellerPrice: '/SellerPriceController/updateSellerPrice'
updateSellerPrice: '/SellerPriceController/updateSellerPrice',
querySellerProductMaterial: '/SellerProductController/querySellerProductMaterial',
addProduct: '/SellerProductController/addProduct'
}
};
... ...
const Context = require('./context');
const request = require('request');
const request = require('request-promise');
const logger = global.yoho.logger;
const defaultOptions = {
resolveWithFullResponse: true
};
const API_ERROR = {
code: 0,
message: '网络异常'
... ... @@ -14,12 +17,10 @@ const API_INTERNAL_ERROR = {
class Api extends Context {
get(url, data, headers) {
return this.parse(() => {
return request.get({
url,
qs: data,
headers
});
return this._request({
url,
qs: data,
headers
});
}
post(url, data, headers) {
... ... @@ -27,48 +28,38 @@ class Api extends Context {
'Content-Type': 'application/json'
};
return this.parse(() => {
return request.post({
url,
body: JSON.stringify(data),
headers: Object.assign(defaultHeader, headers)
});
return this._request({
url,
body: JSON.stringify(data),
headers: Object.assign(defaultHeader, headers)
});
}
upload() {
upload(url, formData, headers) {
let defaultHeader = {
'Content-Type': 'application/json'
};
return this._request({
method: 'post',
url,
formData,
headers: Object.assign(defaultHeader, headers)
});
}
download() {
}
parse(req) {
return new Promise((resolve, reject) => {
let buffers = [];
_request(options) {
options = Object.assign(options, defaultOptions);
req()
.on('error', error => {
if (error) {
logger.error(error);
return reject(API_ERROR);
}
})
.on('data', (chunk) => {
buffers.push(chunk);
})
.on('response', (res) => {
logger.info(`api call ${res.statusCode} [${res.request.method}] ${res.request.href} ${res.request.body}`); // eslint-disable-line
})
.on('end', () => {
if (buffers) {
// TODO 判断文件
try {
let jsonData = JSON.parse(buffers.toString('utf-8'));
return request[options.method || 'get'](options).then(response => {
let jsonBody = JSON.parse(response.body);
let req = response.request;
return resolve(jsonData);
} catch (error) {
return reject(API_INTERNAL_ERROR);
}
}
return reject(API_INTERNAL_ERROR);
});
logger.info(`api call ${req.statusCode} [${req.method}] ${req.uri.href} ${req.uri.query}`);
return jsonBody;
}).catch(err => {
logger.error(err);
return Promise.reject(API_INTERNAL_ERROR);
});
}
}
... ...
/**
* 文件相关controller
* @author: feng.chen<feng.chen@yoho.cn>
* @date: 2017/04/13
*/
'use strict';
const Context = require('../common/context');
const FileService = require('../service/file-service');
const Api = require('../common/api');
const fs = require('fs');
const _ = require('lodash');
class FileController extends Context {
constructor() {
super();
this.api = this.instance(Api);
this.fileService = this.instance(FileService);
}
uploadImage(req, res, next) {
let files = req.files && req.files.file || [];
let errTip = null;
if (!_.isArray(files)) {
files = [files];
}
req.body.files = [];
_.each(files, file => {
let types = file.type.split('/');
if (!types || types[0] !== 'image') {
errTip = '上传文件格式不正确!';
}
if (file.size > 10 * 1024 * 1024) {
errTip = '上传文件尺寸太大!';
}
req.body.files.push(fs.createReadStream(file.path));
req.body.files.push(file.name);
});
if (errTip) {
return res.status(403).send({
message: errTip
});
}
this.api.upload('http://upload.static.yohobuy.com', {
fileData: req.body.files,
project: req.body.bucket
}).then(result => {
if (result.code === 200 && _.get(result, 'data.imagesList.length', 0)) {
result.data.imagesList = _.map(result.data.imagesList, imgUrl => {
return this.fileService.getAbsoluteUrl(imgUrl, req.body.bucket);
});
}
res.json(result);
}).catch(next);
}
}
module.exports = FileController;
... ...
... ... @@ -8,12 +8,16 @@
const Express = require('express');
const UserController = require('./user');
const FileController = require('./file');
const middleware = require('../common/middleware');
const multipart = require('connect-multiparty');
const multipartMiddleware = multipart();
let router = Express.Router(); // eslint-disable-line
router.post('/login', middleware(UserController, 'login'));
router.post('/logout', middleware(UserController, 'logout'));
router.post('/upload/image', multipartMiddleware, middleware(FileController, 'uploadImage'));
module.exports = router;
... ...
... ... @@ -3,7 +3,10 @@
* @author: feng.chen<feng.chen@yoho.cn>
* @date: 2017/04/13
*/
const logger = global.yoho.logger;
module.exports = (err, req, res, next) => { // eslint-disable-line
logger.error(err);
if (err.code === 401) {
return res.status(401).json({
code: 401,
... ...
const Context = require('../common/context');
class FileService extends Context {
constructor() {
super();
}
getAbsoluteUrl(url, bucket) {
if (!url) {
return null;
}
let urlArr = url.split('/'),
stag = urlArr[urlArr.length - 1].substr(0, 2),
domain = `static.yhbimg.com/${bucket}`;
url = domain + url;
if (stag === '01') {
return `//img11.${url}`;
} else if (stag === '03') {
return `//flv01.${url}`;
} else {
return `//img12.${url}`;
}
}
}
module.exports = FileService;
... ...