Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yoho-blk
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
1
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
yyq
9 years ago
Commit
49c91e087173ae5ca515f6576992e85be82690d7
1 parent
0691b88b
获取菜单资源位
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
103 additions
and
5 deletions
apps/partial/views/action/index.hbs
dispatch.js
doraemon/controllers/common.js
doraemon/api/upload.js → doraemon/controllers/upload.js
doraemon/models/common.js
doraemon/router.js
public/js/common/header.js
public/js/plugins/upload.js
apps/partial/views/action/index.hbs
View file @
49c91e0
...
...
@@ -207,7 +207,7 @@
<p
class=
"title"
>
19. 上传图片接口
</p>
<div
stlye=
"width: 200px;height:200px"
>
<form
name=
"form1"
method=
"post"
enctype=
"multipart/form-data"
action=
"/
api
/uploadImg"
>
<form
name=
"form1"
method=
"post"
enctype=
"multipart/form-data"
action=
"/
common
/uploadImg"
>
<input
type=
"file"
name=
"filename"
style=
"width:160px;"
/>
<input
type=
"hidden"
name=
"bucket"
value=
"goodsimg"
/>
<input
type=
"submit"
name=
"Submit"
value=
"上传"
/>
...
...
dispatch.js
View file @
49c91e0
...
...
@@ -8,7 +8,7 @@ module.exports = app => {
// 公共服务
app
.
use
(
'/partial'
,
require
(
'./apps/partial'
));
// 组件demo
app
.
use
(
'/
api'
,
require
(
'./doraemon/router
'
));
// API
app
.
use
(
'/
common'
,
require
(
'./doraemon
'
));
// API
// 业务模块
app
.
use
(
'/passport'
,
require
(
'./apps/passport'
));
...
...
doraemon/controllers/common.js
0 → 100644
View file @
49c91e0
/**
* common controller
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/08/03
*/
'use strict'
;
const
common
=
require
(
'../models/common'
);
/**
* 获取banner
* @function getBanner
* @return { Object } 银行列表
*/
const
getBanner
=
(
req
,
res
,
next
)
=>
{
const
code
=
req
.
query
.
code
;
common
.
getBannerData
(
code
).
then
(
result
=>
{
res
.
json
(
result
);
}).
catch
(
next
);
};
module
.
exports
=
{
getBanner
};
\ No newline at end of file
...
...
doraemon/
api
/upload.js → doraemon/
controllers
/upload.js
View file @
49c91e0
doraemon/models/common.js
0 → 100644
View file @
49c91e0
/**
* common model
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/08/03
*/
'use strict'
;
const
_
=
require
(
'lodash'
);
const
serviceApi
=
global
.
yoho
.
ServiceAPI
;
const
helpers
=
global
.
yoho
.
helpers
;
/**
* 获取资源数据api
* @function _getResourceData
* @param { string } code 资源码
* @return object
*/
const
_getResourceDataAsync
=
(
code
)
=>
{
return
serviceApi
.
get
(
'operations/api/v5/resource/get'
,
{
content_code
:
code
},
{
code
:
200
});
};
const
getBannerData
=
(
code
)
=>
{
return
_getResourceDataAsync
(
code
).
then
(
result
=>
{
let
resData
=
{
code
:
404
,
message
:
'获取资源信息失败'
};
if
(
!
_
.
isEmpty
(
result
.
data
))
{
resData
=
Object
.
assign
({
code
:
200
},
result
.
data
[
0
]);
if
(
resData
.
data
&&
resData
.
data
.
src
)
{
resData
.
data
.
src
=
helpers
.
image
(
resData
.
data
.
src
,
330
,
390
);
}
}
return
resData
;
});
}
module
.
exports
=
{
getBannerData
};
\ No newline at end of file
...
...
doraemon/router.js
View file @
49c91e0
...
...
@@ -7,8 +7,12 @@
'use strict'
;
const
router
=
require
(
'express'
).
Router
();
// eslint-disable-line
const
uploadApi
=
require
(
'./api/upload'
);
const
cRoot
=
'./controllers'
;
const
uploadApi
=
require
(
`
$
{
cRoot
}
/upload`
)
;
const
common
=
require
(
`
$
{
cRoot
}
/common`
)
;
router
.
post
(
'/uploadImg'
,
uploadApi
.
uploadImg
);
router
.
get
(
'/getBanner'
,
common
.
getBanner
);
module
.
exports
=
router
;
...
...
public/js/common/header.js
View file @
49c91e0
...
...
@@ -64,6 +64,21 @@ function refreshBag() {
});
}
function
getNavImg
(
code
,
dom
)
{
$
.
ajax
({
type
:
'GET'
,
url
:
'/common/getBanner'
,
data
:
{
code
:
code
},
success
:
function
(
result
)
{
if
(
result
.
code
===
200
)
{
dom
.
data
(
'show'
,
true
).
html
(
'<img src="'
+
result
.
data
.
src
+
'">'
);
}
}
});
}
refreshBag
();
$
(
'.yoho-group a'
).
hover
(
function
()
{
...
...
@@ -111,7 +126,16 @@ $bagGoodsList.on('click', '.del-good-btn', function() {
$
(
'.contain-third'
).
on
({
mouseenter
:
function
()
{
var
$thirdWrapper
=
$
(
this
).
children
(
'.third-nav-wrapper'
);
var
$thirdWrapper
=
$
(
this
).
children
(
'.third-nav-wrapper'
),
$detail
=
$thirdWrapper
.
find
(
'.show-detail'
);
var
data
;
if
(
$detail
)
{
data
=
$detail
.
data
();
if
(
data
.
code
&&
!
data
.
show
)
{
getNavImg
(
data
.
code
,
$detail
);
}
}
delayer
=
setTimeout
(
function
()
{
$thirdWrapper
.
show
();
...
...
public/js/plugins/upload.js
View file @
49c91e0
...
...
@@ -4,7 +4,7 @@ var $ = require('yoho-jquery'),
var
tpl
=
'<div style="width: 0px; height: 0px; overflow: hidden;">'
+
'<iframe id="yoho-upload-result" name="ajaxUpload" style="display:none"></iframe>'
+
'<form id="yoho-upload" method="post" enctype="multipart/form-data" '
+
'action="/
api
/uploadImg" target="ajaxUpload">'
+
'action="/
common
/uploadImg" target="ajaxUpload">'
+
'<input type="file" name="filename" class="file-name" />'
+
'<input type="hidden" name="bucket" value="goodsimg" />'
+
'</form>'
+
...
...
Please
register
or
login
to post a comment