切换导航条
此项目
正在载入...
登录
何书鹏
/
recruit
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
Karson
7 years ago
提交
483b901cc4d6a1aec63f82e07089e25932cf458d
1 个父辈
5a87939e
修复导入时在表字段超过26时的错误
新增导入Excel文件首行类型配置,默认注释或表字段名 修复表格在字段为null值时的报错
隐藏空白字符变更
内嵌
并排对比
正在显示
4 个修改的文件
包含
40 行增加
和
18 行删除
application/admin/library/traits/Backend.php
application/common/controller/Backend.php
public/assets/js/require-backend.min.js
public/assets/js/require-table.js
application/admin/library/traits/Backend.php
查看文件 @
483b901
...
...
@@ -329,25 +329,35 @@ trait Backend
}
}
//导入文件首行类型,默认是注释,如果需要使用字段名称请使用name
$importHeadType
=
isset
(
$this
->
importHeadType
)
?
$this
->
importHeadType
:
'comment'
;
$table
=
$this
->
model
->
getQuery
()
->
getTable
();
$database
=
\think\Config
::
get
(
'database.database'
);
$fieldArr
=
[];
$list
=
db
()
->
query
(
"SELECT COLUMN_NAME,COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?"
,
[
$table
,
$database
]);
foreach
(
$list
as
$k
=>
$v
)
{
$fieldArr
[
$v
[
'COLUMN_COMMENT'
]]
=
$v
[
'COLUMN_NAME'
];
if
(
$importHeadType
==
'comment'
)
{
$fieldArr
[
$v
[
'COLUMN_COMMENT'
]]
=
$v
[
'COLUMN_NAME'
];
}
else
{
$fieldArr
[
$v
[
'COLUMN_NAME'
]]
=
$v
[
'COLUMN_NAME'
];
}
}
$PHPExcel
=
$PHPReader
->
load
(
$filePath
);
//加载文件
$currentSheet
=
$PHPExcel
->
getSheet
(
0
);
//读取文件中的第一个工作表
$allColumn
=
$currentSheet
->
getHighestColumn
();
//取得最大的列号
$allColumn
=
$currentSheet
->
getHighest
Data
Column
();
//取得最大的列号
$allRow
=
$currentSheet
->
getHighestRow
();
//取得一共有多少行
$maxColumnNumber
=
\PHPExcel_Cell
::
columnIndexFromString
(
$allColumn
);
for
(
$currentRow
=
1
;
$currentRow
<=
1
;
$currentRow
++
)
{
for
(
$currentColumn
=
'A'
;
$currentColumn
<=
$allColumn
;
$currentColumn
++
)
for
(
$currentColumn
=
0
;
$currentColumn
<
$maxColumnNumber
;
$currentColumn
++
)
{
$val
=
$currentSheet
->
getCellByColumnAndRow
(
ord
(
$currentColumn
)
-
65
,
$currentRow
)
->
getValue
();
$val
=
$currentSheet
->
getCellByColumnAndRow
(
$currentColumn
,
$currentRow
)
->
getValue
();
$fields
[]
=
$val
;
}
}
...
...
@@ -355,11 +365,10 @@ trait Backend
for
(
$currentRow
=
2
;
$currentRow
<=
$allRow
;
$currentRow
++
)
{
$values
=
[];
for
(
$currentColumn
=
'A'
;
$currentColumn
<=
$allColumn
;
$currentColumn
++
)
for
(
$currentColumn
=
0
;
$currentColumn
<
$maxColumnNumber
;
$currentColumn
++
)
{
$val
=
$currentSheet
->
getCellByColumnAndRow
(
ord
(
$currentColumn
)
-
65
,
$currentRow
)
->
getValue
();
/* * ord()将字符转为十进制数 */
$val
=
$currentSheet
->
getCellByColumnAndRow
(
$currentColumn
,
$currentRow
)
->
getValue
();
$values
[]
=
is_null
(
$val
)
?
''
:
$val
;
//echo iconv('utf-8','gb2312', $val)."\t";
}
$row
=
[];
$temp
=
array_combine
(
$fields
,
$values
);
...
...
application/common/controller/Backend.php
查看文件 @
483b901
...
...
@@ -78,6 +78,13 @@ class Backend extends Controller
protected
$multiFields
=
'status'
;
/**
* 导入文件首行类型
* 支持comment/name
* 表示注释或字段名
*/
protected
$importHeadType
=
'comment'
;
/**
* 引入后台控制器的traits
*/
use
\app\admin\library\traits\Backend
;
...
...
public/assets/js/require-backend.min.js
查看文件 @
483b901
...
...
@@ -9942,9 +9942,9 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
return
'<img class="'
+
classname
+
'" src="'
+
Fast
.
api
.
cdnurl
(
value
)
+
'" />'
;
},
images
:
function
(
value
,
row
,
index
)
{
value
=
value
.
toString
();
value
=
value
===
null
?
''
:
value
.
toString
();
var
classname
=
typeof
this
.
classname
!==
'undefined'
?
this
.
classname
:
'img-sm img-center'
;
var
arr
=
value
.
toString
().
split
(
','
);
var
arr
=
value
.
split
(
','
);
var
html
=
[];
$
.
each
(
arr
,
function
(
i
,
value
)
{
value
=
value
?
value
:
'/assets/img/blank.gif'
;
...
...
@@ -9959,7 +9959,7 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
if
(
typeof
this
.
custom
!==
'undefined'
)
{
colorArr
=
$
.
extend
(
colorArr
,
this
.
custom
);
}
value
=
value
.
toString
();
value
=
value
===
null
?
''
:
value
.
toString
();
var
color
=
value
&&
typeof
colorArr
[
value
]
!==
'undefined'
?
colorArr
[
value
]
:
'primary'
;
value
=
value
.
charAt
(
0
).
toUpperCase
()
+
value
.
slice
(
1
);
//渲染状态
...
...
@@ -9983,6 +9983,7 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
return
'<a href="'
+
Fast
.
api
.
fixurl
(
url
)
+
'" class="dialogit" data-value="'
+
value
+
'" title="'
+
title
+
'">'
+
value
+
'</a>'
;
},
flag
:
function
(
value
,
row
,
index
)
{
value
=
value
===
null
?
''
:
value
.
toString
();
var
colorArr
=
{
index
:
'success'
,
hot
:
'warning'
,
recommend
:
'danger'
,
'new'
:
'info'
};
//如果字段列有定义custom
if
(
typeof
this
.
custom
!==
'undefined'
)
{
...
...
@@ -9993,9 +9994,9 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
}
//渲染Flag
var
html
=
[];
var
arr
=
value
.
toString
().
split
(
','
);
var
arr
=
value
.
split
(
','
);
$
.
each
(
arr
,
function
(
i
,
value
)
{
value
=
value
.
toString
();
value
=
value
===
null
?
''
:
value
.
toString
();
if
(
value
==
''
)
return
true
;
var
color
=
value
&&
typeof
colorArr
[
value
]
!==
'undefined'
?
colorArr
[
value
]
:
'primary'
;
...
...
@@ -14394,6 +14395,10 @@ define("addtabs", function(){});
if
(
$
(
elem
.
combo_input
).
attr
(
'placeholder'
))
$
(
elem
.
combo_input
).
attr
(
'placeholder_bak'
,
$
(
elem
.
combo_input
).
attr
(
'placeholder'
));
}
if
(
$
(
elem
.
container
).
parent
().
hasClass
(
"input-group"
))
{
$
(
elem
.
container
).
height
(
$
(
elem
.
container
).
parent
().
height
());
}
this
.
elem
=
elem
;
};
...
...
public/assets/js/require-table.js
查看文件 @
483b901
...
...
@@ -341,9 +341,9 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
return
'<img class="'
+
classname
+
'" src="'
+
Fast
.
api
.
cdnurl
(
value
)
+
'" />'
;
},
images
:
function
(
value
,
row
,
index
)
{
value
=
value
.
toString
();
value
=
value
===
null
?
''
:
value
.
toString
();
var
classname
=
typeof
this
.
classname
!==
'undefined'
?
this
.
classname
:
'img-sm img-center'
;
var
arr
=
value
.
toString
().
split
(
','
);
var
arr
=
value
.
split
(
','
);
var
html
=
[];
$
.
each
(
arr
,
function
(
i
,
value
)
{
value
=
value
?
value
:
'/assets/img/blank.gif'
;
...
...
@@ -358,7 +358,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
if
(
typeof
this
.
custom
!==
'undefined'
)
{
colorArr
=
$
.
extend
(
colorArr
,
this
.
custom
);
}
value
=
value
.
toString
();
value
=
value
===
null
?
''
:
value
.
toString
();
var
color
=
value
&&
typeof
colorArr
[
value
]
!==
'undefined'
?
colorArr
[
value
]
:
'primary'
;
value
=
value
.
charAt
(
0
).
toUpperCase
()
+
value
.
slice
(
1
);
//渲染状态
...
...
@@ -382,6 +382,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
return
'<a href="'
+
Fast
.
api
.
fixurl
(
url
)
+
'" class="dialogit" data-value="'
+
value
+
'" title="'
+
title
+
'">'
+
value
+
'</a>'
;
},
flag
:
function
(
value
,
row
,
index
)
{
value
=
value
===
null
?
''
:
value
.
toString
();
var
colorArr
=
{
index
:
'success'
,
hot
:
'warning'
,
recommend
:
'danger'
,
'new'
:
'info'
};
//如果字段列有定义custom
if
(
typeof
this
.
custom
!==
'undefined'
)
{
...
...
@@ -392,9 +393,9 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
}
//渲染Flag
var
html
=
[];
var
arr
=
value
.
toString
().
split
(
','
);
var
arr
=
value
.
split
(
','
);
$
.
each
(
arr
,
function
(
i
,
value
)
{
value
=
value
.
toString
();
value
=
value
===
null
?
''
:
value
.
toString
();
if
(
value
==
''
)
return
true
;
var
color
=
value
&&
typeof
colorArr
[
value
]
!==
'undefined'
?
colorArr
[
value
]
:
'primary'
;
...
...
请
注册
或
登录
后发表评论