Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
P
pica.cloud.web-education-admin
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
Close sidebar
动态
分支图
统计图
创建新议题
提交
议题看板
打开侧边栏
jingqi.liu
pica.cloud.web-education-admin
提交
e9eeaccd
提交
e9eeaccd
编写于
11月 11, 2018
作者:
gjyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test
上级
a0457eab
变更
3
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
519 行增加
和
5 行删除
+519
-5
index-old.js
src/utils/index-old.js
+257
-0
index.1.js
src/utils/index.1.js
+250
-0
index.js
src/utils/index.js
+12
-5
未找到文件。
src/utils/index-old.js
0 → 100644
浏览文件 @
e9eeaccd
/**
* Created by Anndy Yang on 18/03/18.
*/
Date
.
prototype
.
format
=
function
(
fmt
)
{
var
o
=
{
'M+'
:
this
.
getMonth
()
+
1
,
// 月份
'd+'
:
this
.
getDate
(),
// 日
'h+'
:
this
.
getHours
(),
// 小时
'm+'
:
this
.
getMinutes
(),
// 分
's+'
:
this
.
getSeconds
(),
// 秒
'q+'
:
Math
.
floor
((
this
.
getMonth
()
+
3
)
/
3
),
// 季度
'S'
:
this
.
getMilliseconds
()
// 毫秒
}
if
(
/
(
y+
)
/
.
test
(
fmt
))
{
fmt
=
fmt
.
replace
(
RegExp
.
$1
,
(
this
.
getFullYear
()
+
''
).
substr
(
4
-
RegExp
.
$1
.
length
))
}
for
(
var
k
in
o
)
{
if
(
new
RegExp
(
'('
+
k
+
')'
).
test
(
fmt
))
{
fmt
=
fmt
.
replace
(
RegExp
.
$1
,
(
RegExp
.
$1
.
length
===
1
)
?
(
o
[
k
])
:
((
'00'
+
o
[
k
]).
substr
((
''
+
o
[
k
]).
length
)))
}
}
return
fmt
}
export
function
parseTime
(
time
,
cFormat
)
{
if
(
arguments
.
length
===
0
)
{
return
null
}
const
format
=
cFormat
||
'{y}-{m}-{d} {h}:{i}:{s}'
let
date
if
(
typeof
time
===
'object'
)
{
date
=
time
}
else
{
if
((
''
+
time
).
length
===
10
)
time
=
parseInt
(
time
)
*
1000
date
=
new
Date
(
time
)
}
const
formatObj
=
{
y
:
date
.
getFullYear
(),
m
:
date
.
getMonth
()
+
1
,
d
:
date
.
getDate
(),
h
:
date
.
getHours
(),
i
:
date
.
getMinutes
(),
s
:
date
.
getSeconds
(),
a
:
date
.
getDay
()
}
const
time_str
=
format
.
replace
(
/{
(
y|m|d|h|i|s|a
)
+}/g
,
(
result
,
key
)
=>
{
let
value
=
formatObj
[
key
]
if
(
key
===
'a'
)
return
[
'一'
,
'二'
,
'三'
,
'四'
,
'五'
,
'六'
,
'日'
][
value
-
1
]
if
(
result
.
length
>
0
&&
value
<
10
)
{
value
=
'0'
+
value
}
return
value
||
0
})
return
time_str
}
export
function
formatTime
(
time
,
option
)
{
time
=
+
time
*
1000
const
d
=
new
Date
(
time
)
const
now
=
Date
.
now
()
const
diff
=
(
now
-
d
)
/
1000
let
des
=
''
if
(
diff
<
30
)
{
des
=
'刚刚'
}
else
if
(
diff
<
3600
)
{
// less 1 hour
des
=
Math
.
ceil
(
diff
/
60
)
+
'分钟前'
}
else
if
(
diff
<
3600
*
24
)
{
des
=
Math
.
ceil
(
diff
/
3600
)
+
'小时前'
}
else
if
(
diff
<
3600
*
24
*
2
)
{
des
=
'1天前'
}
if
(
option
)
{
return
parseTime
(
time
,
option
)
}
else
{
if
(
des
)
{
return
des
+
' ('
+
(
d
.
getMonth
()
+
1
)
+
'/'
+
d
.
getDate
()
+
' '
+
d
.
getHours
()
+
':'
+
d
.
getMinutes
()
+
':'
+
d
.
getSeconds
()
+
')'
}
else
{
return
d
.
getMonth
()
+
1
+
'/'
+
d
.
getDate
()
+
' '
+
d
.
getHours
()
+
':'
+
d
.
getMinutes
()
+
':'
+
d
.
getSeconds
()
}
}
}
// 将树形结构任意两个key修改成对应的特定key
// {id: '', name: ''} => {id: '', label: ''}
export
function
convertTreeData
(
originData
,
orgId
=
'id'
,
orgLabel
=
'name'
,
targetId
=
'id'
,
targetLabel
=
'label'
)
{
const
targetData
=
[]
let
targetObj
=
{}
for
(
let
i
=
0
;
i
<
originData
.
length
;
i
++
)
{
targetObj
=
{}
targetObj
[
targetId
]
=
originData
[
i
][
orgId
]
targetObj
[
targetLabel
]
=
originData
[
i
][
orgLabel
]
targetData
.
push
(
targetObj
)
if
(
originData
[
i
].
children
&&
originData
[
i
].
children
.
length
>
0
)
{
targetObj
.
children
=
convertTreeData
(
originData
[
i
].
children
,
orgId
,
orgLabel
,
targetId
,
targetLabel
)
}
}
return
targetData
}
/**
* JSON数组去重
* @param: [array] json Array
* @param: [string] 唯一的key名,根据此键名进行去重
*/
export
function
uniqueArray
(
array
,
key
)
{
const
result
=
[
array
[
0
]]
for
(
let
i
=
1
;
i
<
array
.
length
;
i
++
)
{
const
item
=
array
[
i
]
let
repeat
=
false
for
(
let
j
=
0
;
j
<
result
.
length
;
j
++
)
{
if
(
item
[
key
]
===
result
[
j
][
key
])
{
repeat
=
true
break
}
}
if
(
!
repeat
)
{
result
.
push
(
item
)
}
}
return
result
}
export
function
resizeHeight
(
cMinusHeight
=
152
,
iMinuxHeight
=
210
,
refHeightId
=
'sidebarWrapperId'
,
containerHeightId
=
'appContainerId'
,
innerHeightId
=
'elTableId'
)
{
if
(
!
p_getElm
(
refHeightId
)
||
!
p_getElm
(
containerHeightId
)
||
!
p_getElm
(
innerHeightId
))
{
// window.onresize = null
logger
.
warn
(
'No certain dom id!!!'
);
}
let
containerHeight
=
p_getElm
(
refHeightId
).
getBoundingClientRect
().
height
-
50
p_getElm
(
containerHeightId
).
style
.
height
=
containerHeight
-
cMinusHeight
+
'px'
p_getElm
(
innerHeightId
).
style
.
height
=
containerHeight
-
iMinuxHeight
+
'px'
if
(
p_getElm
(
'elTableIdInner'
))
{
p_getElm
(
'elTableIdInner'
).
style
.
height
=
containerHeight
-
iMinuxHeight
+
'px'
}
window
.
onresize
=
function
()
{
containerHeight
=
p_getElm
(
refHeightId
).
getBoundingClientRect
().
height
-
50
p_getElm
(
containerHeightId
).
style
.
height
=
containerHeight
-
cMinusHeight
+
'px'
p_getElm
(
innerHeightId
).
style
.
height
=
containerHeight
-
iMinuxHeight
+
'px'
if
(
p_getElm
(
'elTableIdInner'
))
{
p_getElm
(
'elTableIdInner'
).
style
.
height
=
containerHeight
-
iMinuxHeight
+
'px'
}
}
}
function
p_getElm
(
elmId
)
{
return
document
.
getElementById
(
elmId
)
}
export
function
getHostnameAndPort
()
{
const
NODE_ENV
=
process
.
env
.
NODE_ENV
if
(
NODE_ENV
===
'production'
)
{
return
location
.
hostname
+
':'
+
location
.
port
}
else
{
return
'192.168.80.191:8080'
}
}
function
setRouterParm
(
paramList
)
{
let
parm
=
{};
if
(
paramList
.
length
<=
1
)
{
return
''
;
}
for
(
let
i
=
1
;
i
<
paramList
.
length
;
i
++
)
{
parm
[
paramList
[
i
].
key
]
=
paramList
[
i
].
value
;
}
return
parm
;
}
export
function
setEventByModuleCode
(
itemData
)
{
let
modeCode
=
itemData
.
appModuleInfo
.
code
||
''
;
let
paramList
=
itemData
.
appModuleInfo
.
paramList
?
itemData
.
appModuleInfo
.
paramList
:
''
if
(
modeCode
===
'M001'
||
modeCode
===
'M002'
||
modeCode
===
'M003'
)
{
paramList
=
''
}
else
if
(
modeCode
===
'M100'
||
modeCode
===
'M300'
)
{
let
urlPara
=
getUrlParmByCode
(
paramList
);
paramList
[
0
]
&&
(
paramList
[
0
].
value
+=
urlPara
);
}
else
if
(
modeCode
===
'M400'
)
{
let
path
=
paramList
[
0
][
'key'
];
let
v
=
paramList
[
0
][
'value'
];
let
query
=
setRouterParm
(
paramList
);
//console.log(Vue);
// this.$router.push({
// path: v,
// query:query
// })
}
if
(
typeof
paramList
===
'string'
&&
!
paramList
)
{
paramList
=
[]
}
return
paramList
;
}
function
getUrlParmByCode
(
paramList
)
{
if
(
paramList
.
length
<=
1
)
{
return
''
}
let
dataStr
=
''
let
list
=
[];
for
(
let
i
=
1
;
i
<
paramList
.
length
;
i
++
)
{
list
.
push
(
paramList
[
i
].
key
+
'='
+
paramList
[
i
].
value
)
}
dataStr
=
list
.
join
(
'&'
)
if
(
dataStr
!==
''
)
{
return
'?'
+
dataStr
}
return
''
}
export
function
pageJumpUrl
()
{
let
url
=
{
pageListUrl
:
'https://test1-contents.yunqueyi.com/content_list'
,
detailUrl
:
'https://test1-contents.yunqueyi.com/content_detail'
};
return
url
;
}
// test1地址
const
baseUrl
=
'http://dev-sc.yunqueyi.com/'
||
'http://10.177.10.238:10201/'
||
'http://test1-sc.yunqueyi.com/'
const
apiUrl
=
'http://dev-api.yunqueyi.com/'
||
'http://10.177.10.238:10201'
||
'http://test1-api.yunqueyi.com/'
const
devApiUri
=
'http://dev-api.yunqueyi.com/'
// // uat地址
// const baseUrl = 'http://uat-sc.yunqueyi.com/'
// const apiUrl = 'http://uat-api.yunqueyi.com/'
// // pro地址
// const baseUrl = 'http://sc.yunqueyi.com/'
// const apiUrl = 'http://api.yunqueyi.com/'
// 为每个URL添加应用校验密钥
export
function
getBaseUrl
(
url
,
str
)
{
if
(
str
==
'dev-api'
)
{
return
devApiUri
+
url
}
return
baseUrl
+
url
}
export
function
getApiUrl
(
url
)
{
return
apiUrl
+
url
}
src/utils/index.1.js
0 → 100644
浏览文件 @
e9eeaccd
/**
* Created by Anndy Yang on 18/03/18.
*/
Date
.
prototype
.
format
=
function
(
fmt
)
{
var
o
=
{
'M+'
:
this
.
getMonth
()
+
1
,
// 月份
'd+'
:
this
.
getDate
(),
// 日
'h+'
:
this
.
getHours
(),
// 小时
'm+'
:
this
.
getMinutes
(),
// 分
's+'
:
this
.
getSeconds
(),
// 秒
'q+'
:
Math
.
floor
((
this
.
getMonth
()
+
3
)
/
3
),
// 季度
'S'
:
this
.
getMilliseconds
()
// 毫秒
}
if
(
/
(
y+
)
/
.
test
(
fmt
))
{
fmt
=
fmt
.
replace
(
RegExp
.
$1
,
(
this
.
getFullYear
()
+
''
).
substr
(
4
-
RegExp
.
$1
.
length
))
}
for
(
var
k
in
o
)
{
if
(
new
RegExp
(
'('
+
k
+
')'
).
test
(
fmt
))
{
fmt
=
fmt
.
replace
(
RegExp
.
$1
,
(
RegExp
.
$1
.
length
===
1
)
?
(
o
[
k
])
:
((
'00'
+
o
[
k
]).
substr
((
''
+
o
[
k
]).
length
)))
}
}
return
fmt
}
export
function
parseTime
(
time
,
cFormat
)
{
if
(
arguments
.
length
===
0
)
{
return
null
}
const
format
=
cFormat
||
'{y}-{m}-{d} {h}:{i}:{s}'
let
date
if
(
typeof
time
===
'object'
)
{
date
=
time
}
else
{
if
((
''
+
time
).
length
===
10
)
time
=
parseInt
(
time
)
*
1000
date
=
new
Date
(
time
)
}
const
formatObj
=
{
y
:
date
.
getFullYear
(),
m
:
date
.
getMonth
()
+
1
,
d
:
date
.
getDate
(),
h
:
date
.
getHours
(),
i
:
date
.
getMinutes
(),
s
:
date
.
getSeconds
(),
a
:
date
.
getDay
()
}
const
time_str
=
format
.
replace
(
/{
(
y|m|d|h|i|s|a
)
+}/g
,
(
result
,
key
)
=>
{
let
value
=
formatObj
[
key
]
if
(
key
===
'a'
)
return
[
'一'
,
'二'
,
'三'
,
'四'
,
'五'
,
'六'
,
'日'
][
value
-
1
]
if
(
result
.
length
>
0
&&
value
<
10
)
{
value
=
'0'
+
value
}
return
value
||
0
})
return
time_str
}
export
function
formatTime
(
time
,
option
)
{
time
=
+
time
*
1000
const
d
=
new
Date
(
time
)
const
now
=
Date
.
now
()
const
diff
=
(
now
-
d
)
/
1000
let
des
=
''
if
(
diff
<
30
)
{
des
=
'刚刚'
}
else
if
(
diff
<
3600
)
{
// less 1 hour
des
=
Math
.
ceil
(
diff
/
60
)
+
'分钟前'
}
else
if
(
diff
<
3600
*
24
)
{
des
=
Math
.
ceil
(
diff
/
3600
)
+
'小时前'
}
else
if
(
diff
<
3600
*
24
*
2
)
{
des
=
'1天前'
}
if
(
option
)
{
return
parseTime
(
time
,
option
)
}
else
{
if
(
des
)
{
return
des
+
' ('
+
(
d
.
getMonth
()
+
1
)
+
'/'
+
d
.
getDate
()
+
' '
+
d
.
getHours
()
+
':'
+
d
.
getMinutes
()
+
':'
+
d
.
getSeconds
()
+
')'
}
else
{
return
d
.
getMonth
()
+
1
+
'/'
+
d
.
getDate
()
+
' '
+
d
.
getHours
()
+
':'
+
d
.
getMinutes
()
+
':'
+
d
.
getSeconds
()
}
}
}
// 将树形结构任意两个key修改成对应的特定key
// {id: '', name: ''} => {id: '', label: ''}
export
function
convertTreeData
(
originData
,
orgId
=
'id'
,
orgLabel
=
'name'
,
targetId
=
'id'
,
targetLabel
=
'label'
)
{
const
targetData
=
[]
let
targetObj
=
{}
for
(
let
i
=
0
;
i
<
originData
.
length
;
i
++
)
{
targetObj
=
{}
targetObj
[
targetId
]
=
originData
[
i
][
orgId
]
targetObj
[
targetLabel
]
=
originData
[
i
][
orgLabel
]
targetData
.
push
(
targetObj
)
if
(
originData
[
i
].
children
&&
originData
[
i
].
children
.
length
>
0
)
{
targetObj
.
children
=
convertTreeData
(
originData
[
i
].
children
,
orgId
,
orgLabel
,
targetId
,
targetLabel
)
}
}
return
targetData
}
/**
* JSON数组去重
* @param: [array] json Array
* @param: [string] 唯一的key名,根据此键名进行去重
*/
export
function
uniqueArray
(
array
,
key
)
{
const
result
=
[
array
[
0
]]
for
(
let
i
=
1
;
i
<
array
.
length
;
i
++
)
{
const
item
=
array
[
i
]
let
repeat
=
false
for
(
let
j
=
0
;
j
<
result
.
length
;
j
++
)
{
if
(
item
[
key
]
===
result
[
j
][
key
])
{
repeat
=
true
break
}
}
if
(
!
repeat
)
{
result
.
push
(
item
)
}
}
return
result
}
export
function
resizeHeight
(
cMinusHeight
=
152
,
iMinuxHeight
=
210
,
refHeightId
=
'sidebarWrapperId'
,
containerHeightId
=
'appContainerId'
,
innerHeightId
=
'elTableId'
){
if
(
!
p_getElm
(
refHeightId
)
||
!
p_getElm
(
containerHeightId
)
||
!
p_getElm
(
innerHeightId
))
{
// window.onresize = null
logger
.
warn
(
'No certain dom id!!!'
);
}
let
containerHeight
=
p_getElm
(
refHeightId
).
getBoundingClientRect
().
height
-
50
p_getElm
(
containerHeightId
).
style
.
height
=
containerHeight
-
cMinusHeight
+
'px'
p_getElm
(
innerHeightId
).
style
.
height
=
containerHeight
-
iMinuxHeight
+
'px'
if
(
p_getElm
(
'elTableIdInner'
)){
p_getElm
(
'elTableIdInner'
).
style
.
height
=
containerHeight
-
iMinuxHeight
+
'px'
}
window
.
onresize
=
function
()
{
containerHeight
=
p_getElm
(
refHeightId
).
getBoundingClientRect
().
height
-
50
p_getElm
(
containerHeightId
).
style
.
height
=
containerHeight
-
cMinusHeight
+
'px'
p_getElm
(
innerHeightId
).
style
.
height
=
containerHeight
-
iMinuxHeight
+
'px'
if
(
p_getElm
(
'elTableIdInner'
))
{
p_getElm
(
'elTableIdInner'
).
style
.
height
=
containerHeight
-
iMinuxHeight
+
'px'
}
}
}
function
p_getElm
(
elmId
)
{
return
document
.
getElementById
(
elmId
)
}
export
function
getHostnameAndPort
()
{
const
NODE_ENV
=
process
.
env
.
NODE_ENV
if
(
NODE_ENV
===
'production'
)
{
return
location
.
hostname
+
':'
+
location
.
port
}
else
{
return
'192.168.80.191:8080'
}
}
function
setRouterParm
(
paramList
){
let
parm
=
{};
if
(
paramList
.
length
<=
1
){
return
''
;
}
for
(
let
i
=
1
;
i
<
paramList
.
length
;
i
++
){
parm
[
paramList
[
i
].
key
]
=
paramList
[
i
].
value
;
}
return
parm
;
}
export
function
setEventByModuleCode
(
itemData
){
let
modeCode
=
itemData
.
appModuleInfo
.
code
||
''
;
let
paramList
=
itemData
.
appModuleInfo
.
paramList
?
itemData
.
appModuleInfo
.
paramList
:
''
if
(
modeCode
===
'M001'
||
modeCode
===
'M002'
||
modeCode
===
'M003'
)
{
paramList
=
''
}
else
if
(
modeCode
===
'M100'
||
modeCode
===
'M300'
)
{
let
urlPara
=
getUrlParmByCode
(
paramList
);
paramList
[
0
]
&&
(
paramList
[
0
].
value
+=
urlPara
);
}
else
if
(
modeCode
===
'M400'
)
{
let
path
=
paramList
[
0
][
'key'
];
let
v
=
paramList
[
0
][
'value'
];
let
query
=
setRouterParm
(
paramList
);
//console.log(Vue);
// this.$router.push({
// path: v,
// query:query
// })
}
if
(
typeof
paramList
===
'string'
&&
!
paramList
){
paramList
=
[]
}
return
paramList
;
}
function
getUrlParmByCode
(
paramList
)
{
if
(
paramList
.
length
<=
1
)
{
return
''
}
let
dataStr
=
''
let
list
=
[];
for
(
let
i
=
1
;
i
<
paramList
.
length
;
i
++
)
{
list
.
push
(
paramList
[
i
].
key
+
'='
+
paramList
[
i
].
value
)
}
dataStr
=
list
.
join
(
'&'
)
if
(
dataStr
!==
''
)
{
return
'?'
+
dataStr
}
return
''
}
export
function
pageJumpUrl
(){
let
url
=
{
pageListUrl
:
'https://test1-contents.yunqueyi.com/content_list'
,
detailUrl
:
'https://test1-contents.yunqueyi.com/content_detail'
};
return
url
;
}
// test1地址
// const baseUrl = 'http://dev-sc.yunqueyi.com/' || 'http://10.177.10.238:10201/' || 'http://test1-sc.yunqueyi.com/'
// const apiUrl = 'http://dev-api.yunqueyi.com'http://dev-sc.yunqueyi.com/'/'||'http://10.177.10.238:10201' || 'http://test1-api.yunqueyi.com/'
// const devApiUri = 'http://dev-api.yunqueyi.com/'
// // uat地址
const
baseUrl
=
'http://test1-sc.yunqueyi.com/'
const
apiUrl
=
'http://test1-api.yunqueyi.com/'
// // pro地址
// const baseUrl = 'http://sc.yunqueyi.com/'
// const apiUrl = 'http://api.yunqueyi.com/'
// 为每个URL添加应用校验密钥
export
function
getBaseUrl
(
url
,
str
)
{
return
baseUrl
+
url
}
export
function
getApiUrl
(
url
)
{
return
apiUrl
+
url
}
src/utils/index.js
浏览文件 @
e9eeaccd
...
...
@@ -226,14 +226,14 @@ export function pageJumpUrl(){
// test1地址
//
const baseUrl = 'http://dev-sc.yunqueyi.com/' || 'http://10.177.10.238:10201/' || 'http://test1-sc.yunqueyi.com/'
// const apiUrl = 'http://dev-api.yunqueyi.com'http://dev-sc.yunqueyi.com/'
/'||'http://10.177.10.238:10201' || 'http://test1-api.yunqueyi.com/'
//
const devApiUri = 'http://dev-api.yunqueyi.com/'
const
baseUrl
=
'http://dev-sc.yunqueyi.com/'
||
'http://10.177.10.238:10201/'
||
'http://test1-sc.yunqueyi.com/'
const
apiUrl
=
'http://dev-api.yunqueyi.com
/'
||
'http://10.177.10.238:10201'
||
'http://test1-api.yunqueyi.com/'
const
devApiUri
=
'http://dev-api.yunqueyi.com/'
// // uat地址
const
baseUrl
=
'http://test1
-sc.yunqueyi.com/'
const
apiUrl
=
'http://test1
-api.yunqueyi.com/'
// const baseUrl = 'http://uat
-sc.yunqueyi.com/'
// const apiUrl = 'http://uat
-api.yunqueyi.com/'
// // pro地址
// const baseUrl = 'http://sc.yunqueyi.com/'
...
...
@@ -242,9 +242,16 @@ const apiUrl = 'http://test1-api.yunqueyi.com/'
// 为每个URL添加应用校验密钥
export
function
getBaseUrl
(
url
,
str
)
{
if
(
str
==
'dev-api'
){
return
devApiUri
+
url
}
return
baseUrl
+
url
}
export
function
getApiUrl
(
url
)
{
return
apiUrl
+
url
}
写
预览
Markdown
格式
0%
请重试
or
附加一个文件
附加文件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录