后台批量导入
This commit is contained in:
parent
2659e5130a
commit
5f1fa5e503
@ -5,6 +5,8 @@ namespace plugin\admin\app\controller;
|
||||
use app\common\model\StudentParent;
|
||||
use app\common\model\StudentSchedule;
|
||||
use app\constant\ResponseCode;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use plugin\admin\app\model\Student;
|
||||
@ -38,7 +40,10 @@ class StudentController extends Crud
|
||||
*/
|
||||
public function index(): Response
|
||||
{
|
||||
return view('student/index');
|
||||
// 导入模板文件
|
||||
$import_example = 'https://lxpk.lingruikj.com/files/xlsx/202408/2024080322474292.xlsx';
|
||||
$example_name = '学生家长导入模板数据.xlsx';
|
||||
return view('student/index', ['import_example' => $import_example, 'example_name' => $example_name]);
|
||||
}
|
||||
|
||||
public function select(Request $request): Response
|
||||
@ -47,10 +52,16 @@ class StudentController extends Crud
|
||||
|
||||
$data = $request->get();
|
||||
|
||||
$student = \app\common\model\Student::order('id asc');
|
||||
$student = \app\common\model\Student::order('id desc');
|
||||
if (isset($data['id']) && $data['id']) {
|
||||
$student->where(['id' => $data['id']]);
|
||||
}
|
||||
if(isset($data['account']) && $data['account']){
|
||||
$student->where('account' ,'like', '%' . $data['account'] . '%');
|
||||
}
|
||||
if(isset($data['student_name']) && $data['student_name']){
|
||||
$student->where('student_name' ,'like', '%' . $data['student_name'] . '%');
|
||||
}
|
||||
|
||||
$limit = (int)$request->get('limit', 10);
|
||||
$limit = $limit <= 0 ? 10 : $limit;
|
||||
@ -264,4 +275,109 @@ class StudentController extends Crud
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc 导入教师数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function importStudentAccount(Request $request)
|
||||
{
|
||||
try {
|
||||
ini_set('memory_limit', '256M');
|
||||
$file = $request->file('file');
|
||||
if ($file && $file->isValid()) {
|
||||
$ext = $file->getUploadExtension();
|
||||
if (!in_array($ext, ['xlsx', 'xls', 'csv'])) {
|
||||
throw new Exception('上传文件格式错误');
|
||||
}
|
||||
$uploadDir = '/files/xlsx/' . date('Ym') . '/';
|
||||
$filename = date('YmdHis') . rand(10, 99);
|
||||
$uploadPath = $uploadDir . $filename . '.' . $ext;
|
||||
$rootUploadDir = public_path($uploadPath);
|
||||
$file->move($rootUploadDir);
|
||||
|
||||
//读取表格数据,插入数据库
|
||||
$objRead = IOFactory::createReader('Xlsx');
|
||||
|
||||
if (!$objRead->canRead($rootUploadDir)) {
|
||||
/** @var Xls $objRead */
|
||||
$objRead = IOFactory::createReader('Xls');
|
||||
|
||||
if (!$objRead->canRead($rootUploadDir)) {
|
||||
throw new Exception('只支持导入Excel文件!');
|
||||
}
|
||||
}
|
||||
/* 如果不需要获取特殊操作,则只读内容,可以大幅度提升读取Excel效率 */
|
||||
$objRead->setReadDataOnly(true);
|
||||
|
||||
/* 建立excel对象 */
|
||||
$obj = $objRead->load($rootUploadDir);
|
||||
/* 获取指定的sheet表 */
|
||||
$currSheet = $obj->getSheet(0);
|
||||
/* 取得最大的列号 */
|
||||
$columnH = $currSheet->getHighestColumn();
|
||||
/* 兼容原逻辑,循环时使用的是小于等于 */
|
||||
$columnCnt = Coordinate::columnIndexFromString($columnH);
|
||||
|
||||
/* 获取总行数 */
|
||||
$rowCnt = $currSheet->getHighestRow();
|
||||
|
||||
if ($rowCnt <= 1) {
|
||||
throw new Exception('不能上传空数据');
|
||||
}
|
||||
|
||||
$success_count = 0;
|
||||
$error_count = 0;
|
||||
$msg = '';
|
||||
// 遍历每一行
|
||||
|
||||
for ($row = 2; $row <= $rowCnt; $row++) {
|
||||
// 遍历每一列
|
||||
$account = trim($currSheet->getCell('A' . $row)->getValue() ?: '');
|
||||
$student_name = trim($currSheet->getCell('B' . $row)->getValue() ?: '');
|
||||
if($account && $student_name){
|
||||
$password = trim($currSheet->getCell('C' . $row)->getValue() ?: '');
|
||||
$salt = random_str(16);
|
||||
if (empty($password)) {
|
||||
$password = trim(explode(' ', $account)[0]) . '001';
|
||||
}
|
||||
//查找教师数据是否存在
|
||||
$parent = \app\common\model\Student::where(['account' => $account, 'student_name' => $student_name])->findOrEmpty();
|
||||
if ($parent->isEmpty()) {
|
||||
$password = md5($password . $salt);
|
||||
\app\common\model\Student::create([
|
||||
'account' => $account,
|
||||
'student_name' => $student_name,
|
||||
'password' => $password,
|
||||
'salt' => $salt,
|
||||
]);
|
||||
$success_count++;
|
||||
} else {
|
||||
$error_count++;
|
||||
$msg .= '【' . $student_name . '】';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
$return_msg = '成功【' . $success_count . '】条,' . '失败【' . $error_count . '】条';
|
||||
if ($error_count) {
|
||||
$return_msg .= ',失败数据' . $msg . '已存在';
|
||||
}
|
||||
|
||||
return json([
|
||||
'code' => ResponseCode::WEB_API_SUCCESS,
|
||||
'data' => [],
|
||||
'msg' => $return_msg
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
return json([
|
||||
'code' => ResponseCode::WEB_API_FAIL,
|
||||
'msg' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
namespace plugin\admin\app\controller;
|
||||
|
||||
use app\constant\ResponseCode;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use plugin\admin\app\model\StudentParent;
|
||||
@ -11,11 +13,11 @@ use support\exception\BusinessException;
|
||||
use think\Exception;
|
||||
|
||||
/**
|
||||
* 家长管理
|
||||
* 家长管理
|
||||
*/
|
||||
class StudentParentController extends Crud
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @var StudentParent
|
||||
*/
|
||||
@ -29,14 +31,17 @@ class StudentParentController extends Crud
|
||||
{
|
||||
$this->model = new StudentParent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 浏览
|
||||
* @return Response
|
||||
*/
|
||||
public function index(): Response
|
||||
{
|
||||
return view('student-parent/index');
|
||||
// 导入模板文件
|
||||
$import_example = 'https://lxpk.lingruikj.com/files/xlsx/202408/2024080322474292.xlsx';
|
||||
$example_name = '学生家长导入模板数据.xlsx';
|
||||
return view('student-parent/index', ['import_example' => $import_example, 'example_name' => $example_name]);
|
||||
}
|
||||
|
||||
public function select(Request $request): Response
|
||||
@ -113,7 +118,7 @@ class StudentParentController extends Crud
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
* @throws BusinessException
|
||||
*/
|
||||
*/
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
if ($request->method() === 'POST') {
|
||||
@ -180,7 +185,7 @@ class StudentParentController extends Crud
|
||||
'salt' => $salt,
|
||||
'password' => $password
|
||||
]);
|
||||
if(!$res){
|
||||
if (!$res) {
|
||||
throw new Exception('重置失败');
|
||||
}
|
||||
|
||||
@ -196,4 +201,110 @@ class StudentParentController extends Crud
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @desc 导入教师数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function importParentAccount(Request $request)
|
||||
{
|
||||
try {
|
||||
ini_set('memory_limit', '256M');
|
||||
$file = $request->file('file');
|
||||
if ($file && $file->isValid()) {
|
||||
$ext = $file->getUploadExtension();
|
||||
if (!in_array($ext, ['xlsx', 'xls', 'csv'])) {
|
||||
throw new Exception('上传文件格式错误');
|
||||
}
|
||||
$uploadDir = '/files/xlsx/' . date('Ym') . '/';
|
||||
$filename = date('YmdHis') . rand(10, 99);
|
||||
$uploadPath = $uploadDir . $filename . '.' . $ext;
|
||||
$rootUploadDir = public_path($uploadPath);
|
||||
$file->move($rootUploadDir);
|
||||
|
||||
|
||||
//读取表格数据,插入数据库
|
||||
$objRead = IOFactory::createReader('Xlsx');
|
||||
|
||||
if (!$objRead->canRead($rootUploadDir)) {
|
||||
/** @var Xls $objRead */
|
||||
$objRead = IOFactory::createReader('Xls');
|
||||
|
||||
if (!$objRead->canRead($rootUploadDir)) {
|
||||
throw new Exception('只支持导入Excel文件!');
|
||||
}
|
||||
}
|
||||
/* 如果不需要获取特殊操作,则只读内容,可以大幅度提升读取Excel效率 */
|
||||
$objRead->setReadDataOnly(true);
|
||||
|
||||
/* 建立excel对象 */
|
||||
$obj = $objRead->load($rootUploadDir);
|
||||
/* 获取指定的sheet表 */
|
||||
$currSheet = $obj->getSheet(0);
|
||||
/* 取得最大的列号 */
|
||||
$columnH = $currSheet->getHighestColumn();
|
||||
/* 兼容原逻辑,循环时使用的是小于等于 */
|
||||
$columnCnt = Coordinate::columnIndexFromString($columnH);
|
||||
|
||||
/* 获取总行数 */
|
||||
$rowCnt = $currSheet->getHighestRow();
|
||||
|
||||
if ($rowCnt <= 1) {
|
||||
throw new Exception('不能上传空数据');
|
||||
}
|
||||
|
||||
$success_count = 0;
|
||||
$error_count = 0;
|
||||
$msg = '';
|
||||
// 遍历每一行
|
||||
|
||||
for ($row = 2; $row <= $rowCnt; $row++) {
|
||||
// 遍历每一列
|
||||
$account = trim($currSheet->getCell('A' . $row)->getValue() ?: '');
|
||||
$parent_name = trim($currSheet->getCell('B' . $row)->getValue() ?: '');
|
||||
if($account && $parent_name){
|
||||
$password = trim($currSheet->getCell('C' . $row)->getValue() ?: '');
|
||||
$salt = random_str(16);
|
||||
if (empty($password)) {
|
||||
$password = trim(mb_substr($account, 0, -2)) . '001';
|
||||
}
|
||||
//查找教师数据是否存在
|
||||
$parent = \app\common\model\StudentParent::where(['account' => $account, 'parent_name' => $parent_name])->findOrEmpty();
|
||||
if ($parent->isEmpty()) {
|
||||
$password = md5($password . $salt);
|
||||
\app\common\model\StudentParent::create([
|
||||
'account' => $account,
|
||||
'parent_name' => $parent_name,
|
||||
'password' => $password,
|
||||
'salt' => $salt,
|
||||
]);
|
||||
$success_count++;
|
||||
} else {
|
||||
$error_count++;
|
||||
$msg .= '【' . $parent_name . '】';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
$return_msg = '成功【' . $success_count . '】条,' . '失败【' . $error_count . '】条';
|
||||
if ($error_count) {
|
||||
$return_msg .= ',失败数据' . $msg . '已存在';
|
||||
}
|
||||
|
||||
return json([
|
||||
'code' => ResponseCode::WEB_API_SUCCESS,
|
||||
'data' => [],
|
||||
'msg' => $return_msg
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
return json([
|
||||
'code' => ResponseCode::WEB_API_FAIL,
|
||||
'msg' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ use app\common\model\Subject;
|
||||
use app\common\model\TeacherScheduleTime;
|
||||
use app\common\model\TimeZone;
|
||||
use app\constant\ResponseCode;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use plugin\admin\app\model\Teacher;
|
||||
@ -41,7 +43,10 @@ class TeacherController extends Crud
|
||||
*/
|
||||
public function index(): Response
|
||||
{
|
||||
return view('teacher/index');
|
||||
// 导入模板文件
|
||||
$import_example = 'https://lxpk.lingruikj.com/files/xlsx/202408/2024080322192257.xlsx';
|
||||
$example_name = '教师导入模板数据.xlsx';
|
||||
return view('teacher/index', ['import_example' => $import_example, 'example_name' => $example_name]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -331,4 +336,111 @@ class TeacherController extends Crud
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @desc 导入教师数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function importTeacherAccount(Request $request)
|
||||
{
|
||||
try {
|
||||
ini_set('memory_limit', '256M');
|
||||
$file = $request->file('file');
|
||||
if ($file && $file->isValid()) {
|
||||
$ext = $file->getUploadExtension();
|
||||
if (!in_array($ext, ['xlsx', 'xls', 'csv'])) {
|
||||
throw new Exception('上传文件格式错误');
|
||||
}
|
||||
$uploadDir = '/files/xlsx/' . date('Ym') . '/';
|
||||
$filename = date('YmdHis') . rand(10, 99);
|
||||
$uploadPath = $uploadDir . $filename . '.' . $ext;
|
||||
$rootUploadDir = public_path($uploadPath);
|
||||
$file->move($rootUploadDir);
|
||||
|
||||
|
||||
//读取表格数据,插入数据库
|
||||
$objRead = IOFactory::createReader('Xlsx');
|
||||
|
||||
if (!$objRead->canRead($rootUploadDir)) {
|
||||
/** @var Xls $objRead */
|
||||
$objRead = IOFactory::createReader('Xls');
|
||||
|
||||
if (!$objRead->canRead($rootUploadDir)) {
|
||||
throw new Exception('只支持导入Excel文件!');
|
||||
}
|
||||
}
|
||||
/* 如果不需要获取特殊操作,则只读内容,可以大幅度提升读取Excel效率 */
|
||||
$objRead->setReadDataOnly(true);
|
||||
|
||||
/* 建立excel对象 */
|
||||
$obj = $objRead->load($rootUploadDir);
|
||||
/* 获取指定的sheet表 */
|
||||
$currSheet = $obj->getSheet(0);
|
||||
/* 取得最大的列号 */
|
||||
$columnH = $currSheet->getHighestColumn();
|
||||
/* 兼容原逻辑,循环时使用的是小于等于 */
|
||||
$columnCnt = Coordinate::columnIndexFromString($columnH);
|
||||
|
||||
/* 获取总行数 */
|
||||
$rowCnt = $currSheet->getHighestRow();
|
||||
|
||||
if ($rowCnt <= 1) {
|
||||
throw new Exception('不能上传空数据');
|
||||
}
|
||||
|
||||
$success_count = 0;
|
||||
$error_count = 0;
|
||||
$msg = '';
|
||||
// 遍历每一行
|
||||
for ($row = 2; $row <= $rowCnt; $row++) {
|
||||
// 遍历每一列
|
||||
|
||||
$account = trim($currSheet->getCell('A' . $row)->getValue() ?: '');
|
||||
$teacher_name = trim($currSheet->getCell('B' . $row)->getValue() ?: '');
|
||||
|
||||
if($account && $teacher_name){
|
||||
|
||||
$password = trim($currSheet->getCell('C' . $row)->getValue() ?: '');
|
||||
$salt = random_str(16);
|
||||
if (empty($password)) {
|
||||
$password = 'YD' . $account . '123';
|
||||
}
|
||||
//查找教师数据是否存在
|
||||
$teacher = \app\common\model\Teacher::where(['account' => $account, 'teacher_name' => $teacher_name])->findOrEmpty();
|
||||
if ($teacher->isEmpty()) {
|
||||
$password = md5($password . $salt);
|
||||
\app\common\model\Teacher::create([
|
||||
'account' => $account,
|
||||
'teacher_name' => $teacher_name,
|
||||
'password' => $password,
|
||||
'salt' => $salt,
|
||||
]);
|
||||
$success_count++;
|
||||
} else {
|
||||
$error_count++;
|
||||
$msg .= '【' . $teacher_name . '】';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
$return_msg = '成功【' . $success_count . '】条,' . '失败【' . $error_count . '】条';
|
||||
if ($error_count) {
|
||||
$return_msg .= ',失败数据' . $msg . '已存在';
|
||||
}
|
||||
|
||||
return json([
|
||||
'code' => ResponseCode::WEB_API_SUCCESS,
|
||||
'data' => [],
|
||||
'msg' => $return_msg
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
return json([
|
||||
'code' => ResponseCode::WEB_API_FAIL,
|
||||
'msg' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -107,8 +107,8 @@
|
||||
|
||||
<!-- 表格行工具栏 -->
|
||||
<script type="text/html" id="table-bar">
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="edit" permission="app.admin.studentfeedback.update">详情</button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="remove" permission="app.admin.studentfeedback.delete">删除</button>
|
||||
<button type="button" class="layui-btn layui-btn-xs" lay-event="edit" permission="app.admin.studentfeedback.update">详情</button>
|
||||
<button type="button" class="layui-btn layui-btn-xs layui-bg-red" lay-event="remove" permission="app.admin.studentfeedback.delete">删除</button>
|
||||
</script>
|
||||
|
||||
<script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
|
||||
|
@ -98,8 +98,8 @@
|
||||
|
||||
<!-- 表格行工具栏 -->
|
||||
<script type="text/html" id="table-bar">
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="edit" permission="app.admin.studenthomework.update">编辑</button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="remove" permission="app.admin.studenthomework.delete">删除</button>
|
||||
<button type="button" class="layui-btn layui-btn-xs" lay-event="edit" permission="app.admin.studenthomework.update">编辑</button>
|
||||
<button type="button" class="layui-btn layui-btn-xs layui-bg-red" lay-event="remove" permission="app.admin.studenthomework.delete">删除</button>
|
||||
</script>
|
||||
|
||||
<script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
|
||||
|
@ -56,6 +56,9 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="pear-btn pear-btn-primary pear-btn-md" id="upload_parent_info" permission="app.admin.teacher.insert" style="display: none">
|
||||
<i class="layui-icon layui-icon-upload"></i>批量导入账号
|
||||
</button>
|
||||
<!-- 表格顶部工具栏 -->
|
||||
<script type="text/html" id="table-toolbar">
|
||||
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add" permission="app.admin.studentparent.insert">
|
||||
@ -64,15 +67,22 @@
|
||||
<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove" permission="app.admin.studentparent.delete">
|
||||
<i class="layui-icon layui-icon-delete"></i>删除
|
||||
</button>
|
||||
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="import" permission="app.admin.teacher.insert">
|
||||
<i class="layui-icon layui-icon-upload"></i>批量导入账号
|
||||
</button>
|
||||
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="download_example" permission="app.admin.teacher.insert">
|
||||
<i class="layui-icon layui-icon-download-circle"></i>下载导入模板
|
||||
</button>
|
||||
</script>
|
||||
|
||||
<!-- 表格行工具栏 -->
|
||||
<script type="text/html" id="table-bar">
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="edit" permission="app.admin.studentparent.update">编辑</button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="rest_password" permission="app.admin.teacher.update">重置密码</button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="remove" permission="app.admin.studentparent.delete">删除</button>
|
||||
<button type="button" class="layui-btn layui-btn-xs" lay-event="edit" permission="app.admin.studentparent.update">编辑</button>
|
||||
<button type="button" class="layui-btn layui-btn-xs layui-bg-blue" lay-event="rest_password" permission="app.admin.teacher.update">重置密码</button>
|
||||
<button type="button" class="layui-btn layui-btn-xs layui-bg-red" lay-event="remove" permission="app.admin.studentparent.delete">删除</button>
|
||||
</script>
|
||||
|
||||
|
||||
<script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
|
||||
<script src="/app/admin/component/pear/pear.js"></script>
|
||||
<script src="/app/admin/admin/js/permission.js"></script>
|
||||
@ -82,12 +92,30 @@
|
||||
|
||||
// 相关常量
|
||||
const PRIMARY_KEY = "id";
|
||||
const SELECT_API = "/app/admin/student-parent/select";
|
||||
const SELECT_API = "/app/admin/student-parent/select?field=id&order=desc";
|
||||
const UPDATE_API = "/app/admin/student-parent/update";
|
||||
const DELETE_API = "/app/admin/student-parent/delete";
|
||||
const INSERT_URL = "/app/admin/student-parent/insert";
|
||||
const UPDATE_URL = "/app/admin/student-parent/update";
|
||||
|
||||
|
||||
|
||||
|
||||
// 字段 头像 avatar
|
||||
layui.use(["upload", "layer"], function() {
|
||||
layui.upload.render({
|
||||
elem: "#upload_parent_info",
|
||||
accept: 'file', //普通文件
|
||||
acceptMime: ".xls,.xlsx",
|
||||
url: "/app/admin/studentParent/importParentAccount",
|
||||
field: "file",
|
||||
done: function (res) {
|
||||
layer.alert(res.msg, {icon: 1}, function(index){
|
||||
layer.close(index);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 表格渲染
|
||||
layui.use(["table", "form", "common", "popup", "util"], function() {
|
||||
let table = layui.table;
|
||||
@ -195,7 +223,20 @@
|
||||
table.on("toolbar(data-table)", function(obj) {
|
||||
if (obj.event === "add") {
|
||||
add();
|
||||
} else if (obj.event === "refresh") {
|
||||
}else if (obj.event === "import") {
|
||||
import_file();
|
||||
} else if (obj.event === "download_example") {
|
||||
const link = document.createElement('a');
|
||||
link.style.display = 'none';
|
||||
// 设置下载地址
|
||||
link.setAttribute('href', '{$import_example}');
|
||||
// 设置文件名
|
||||
link.setAttribute('download', '{$example_name}');
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
// window.location.href = '{$import_example}';
|
||||
} else if (obj.event === "refresh") {
|
||||
refreshTable();
|
||||
} else if (obj.event === "batchRemove") {
|
||||
batchRemove(obj);
|
||||
@ -242,6 +283,10 @@
|
||||
});
|
||||
});
|
||||
|
||||
let import_file = function() {
|
||||
$('#upload_parent_info').click();
|
||||
}
|
||||
|
||||
// 表格新增数据
|
||||
let add = function() {
|
||||
layer.open({
|
||||
|
@ -126,7 +126,7 @@
|
||||
<!-- 表格行工具栏 -->
|
||||
<script type="text/html" id="table-bar">
|
||||
<!-- <button class="pear-btn pear-btn-xs tool-btn" lay-event="edit" permission="app.admin.studentschedule.update">编辑</button>-->
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="remove" permission="app.admin.studentschedule.delete">
|
||||
<button type="button" class="layui-btn layui-btn-xs layui-bg-red" lay-event="remove" permission="app.admin.studentschedule.delete">
|
||||
删除
|
||||
</button>
|
||||
</script>
|
||||
|
@ -9,6 +9,45 @@
|
||||
<body class="pear-container">
|
||||
|
||||
<!-- 顶部查询表单 -->
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-body">
|
||||
<form class="layui-form top-search-from">
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">账号</label>
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-input-block">
|
||||
<input type="text" autocomplete="off" name="account" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">姓名</label>
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-input-block">
|
||||
<input type="text" autocomplete="off" name="student_name" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="layui-form-item layui-inline">
|
||||
<label class="layui-form-label"></label>
|
||||
<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="table-query">
|
||||
<i class="layui-icon layui-icon-search"></i>查询
|
||||
</button>
|
||||
<button type="reset" class="pear-btn pear-btn-md" lay-submit lay-filter="table-reset">
|
||||
<i class="layui-icon layui-icon-refresh"></i>重置
|
||||
</button>
|
||||
</div>
|
||||
<div class="toggle-btn">
|
||||
<a class="layui-hide">展开<i class="layui-icon layui-icon-down"></i></a>
|
||||
<a class="layui-hide">收起<i class="layui-icon layui-icon-up"></i></a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- 数据表格 -->
|
||||
@ -18,6 +57,9 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="pear-btn pear-btn-primary pear-btn-md" id="upload_student_info" permission="app.admin.teacher.insert" style="display: none">
|
||||
<i class="layui-icon layui-icon-upload"></i>批量导入账号
|
||||
</button>
|
||||
<!-- 表格顶部工具栏 -->
|
||||
<script type="text/html" id="table-toolbar">
|
||||
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add" permission="app.admin.student.insert">
|
||||
@ -26,16 +68,22 @@
|
||||
<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove" permission="app.admin.student.delete">
|
||||
<i class="layui-icon layui-icon-delete"></i>删除
|
||||
</button>
|
||||
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="import" permission="app.admin.teacher.insert">
|
||||
<i class="layui-icon layui-icon-upload"></i>批量导入账号
|
||||
</button>
|
||||
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="download_example" permission="app.admin.teacher.insert">
|
||||
<i class="layui-icon layui-icon-download-circle"></i>下载导入模板
|
||||
</button>
|
||||
</script>
|
||||
|
||||
<!-- 表格行工具栏 -->
|
||||
<script type="text/html" id="table-bar">
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="edit" permission="app.admin.student.update">编辑</button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="check_schedule" permission="app.admin.student.update">查看课表</button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="rest_password" permission="app.admin.teacher.update">
|
||||
<button type="button" class="layui-btn layui-btn-xs" lay-event="edit" permission="app.admin.student.update">编辑</button>
|
||||
<button type="button" class="layui-btn layui-btn-xs layui-bg-orange" lay-event="check_schedule" permission="app.admin.student.update">查看课表</button>
|
||||
<button type="button" class="layui-btn layui-btn-xs layui-bg-blue" lay-event="rest_password" permission="app.admin.teacher.update">
|
||||
重置密码
|
||||
</button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="remove" permission="app.admin.student.delete">删除</button>
|
||||
<button type="button" class="layui-btn layui-btn-xs layui-bg-red" lay-event="remove" permission="app.admin.student.delete">删除</button>
|
||||
</script>
|
||||
|
||||
<script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
|
||||
@ -53,6 +101,23 @@
|
||||
const INSERT_URL = "/app/admin/student/insert";
|
||||
const UPDATE_URL = "/app/admin/student/update";
|
||||
|
||||
|
||||
// 字段 头像 avatar
|
||||
layui.use(["upload", "layer"], function() {
|
||||
layui.upload.render({
|
||||
elem: "#upload_student_info",
|
||||
accept: 'file', //普通文件
|
||||
acceptMime: ".xls,.xlsx",
|
||||
url: "/app/admin/student/importStudentAccount",
|
||||
field: "file",
|
||||
done: function (res) {
|
||||
layer.alert(res.msg, {icon: 1}, function(index){
|
||||
layer.close(index);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 表格渲染
|
||||
layui.use(["table", "form", "common", "popup", "util"], function () {
|
||||
let table = layui.table;
|
||||
@ -124,7 +189,7 @@
|
||||
toolbar: "#table-bar",
|
||||
align: "center",
|
||||
fixed: "right",
|
||||
width: 220,
|
||||
width: 265,
|
||||
}
|
||||
];
|
||||
|
||||
@ -155,7 +220,7 @@
|
||||
remove(obj);
|
||||
} else if (obj.event === "edit") {
|
||||
edit(obj);
|
||||
} else if (obj.event === "check_schedule") {
|
||||
}else if (obj.event === "check_schedule") {
|
||||
check_schedule(obj);
|
||||
} else if (obj.event === "rest_password") {
|
||||
rest_password(obj);
|
||||
@ -166,7 +231,21 @@
|
||||
table.on("toolbar(data-table)", function (obj) {
|
||||
if (obj.event === "add") {
|
||||
add();
|
||||
} else if (obj.event === "refresh") {
|
||||
}else if (obj.event === "import") {
|
||||
console.log(obj.event)
|
||||
import_file();
|
||||
} else if (obj.event === "download_example") {
|
||||
const link = document.createElement('a');
|
||||
link.style.display = 'none';
|
||||
// 设置下载地址
|
||||
link.setAttribute('href', '{$import_example}');
|
||||
// 设置文件名
|
||||
link.setAttribute('download', '{$example_name}');
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
// window.location.href = '{$import_example}';
|
||||
} else if (obj.event === "refresh") {
|
||||
refreshTable();
|
||||
} else if (obj.event === "batchRemove") {
|
||||
batchRemove(obj);
|
||||
@ -213,6 +292,10 @@
|
||||
});
|
||||
});
|
||||
|
||||
let import_file = function() {
|
||||
$('#upload_student_info').click();
|
||||
}
|
||||
|
||||
// 表格新增数据
|
||||
let add = function () {
|
||||
layer.open({
|
||||
|
@ -121,9 +121,9 @@
|
||||
|
||||
<!-- 表格行工具栏 -->
|
||||
<script type="text/html" id="table-bar">
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="edit" permission="app.admin.subjecthomework.update">详情
|
||||
<button type="button" class="layui-btn layui-btn-xs" lay-event="edit" permission="app.admin.subjecthomework.update">详情
|
||||
</button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="remove" permission="app.admin.subjecthomework.delete">
|
||||
<button type="button" class="layui-btn layui-btn-xs layui-bg-red" lay-event="remove" permission="app.admin.subjecthomework.delete">
|
||||
删除
|
||||
</button>
|
||||
</script>
|
||||
|
@ -70,8 +70,8 @@
|
||||
|
||||
<!-- 表格行工具栏 -->
|
||||
<script type="text/html" id="table-bar">
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="edit" permission="app.admin.subject.update">编辑</button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="remove" permission="app.admin.subject.delete">删除</button>
|
||||
<button type="button" class="layui-btn layui-btn-xs" lay-event="edit" permission="app.admin.subject.update">编辑</button>
|
||||
<button type="button" class="layui-btn layui-btn-xs layui-bg-red" lay-event="remove" permission="app.admin.subject.delete">删除</button>
|
||||
</script>
|
||||
|
||||
<script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
|
||||
|
@ -24,6 +24,10 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 默认排序 -->
|
||||
<!-- <input type="hidden" autocomplete="off" name="field" value="id" class="layui-input inline-block">-->
|
||||
<!-- <input type="hidden" autocomplete="off" name="order" value="desc" class="layui-input inline-block">-->
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">教师姓名</label>
|
||||
<div class="layui-input-block">
|
||||
@ -68,6 +72,9 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="pear-btn pear-btn-primary pear-btn-md" id="upload_teacher_info" permission="app.admin.teacher.insert" style="display: none">
|
||||
<i class="layui-icon layui-icon-upload"></i>批量导入账号
|
||||
</button>
|
||||
<!-- 表格顶部工具栏 -->
|
||||
<script type="text/html" id="table-toolbar">
|
||||
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add" permission="app.admin.teacher.insert">
|
||||
@ -76,6 +83,12 @@
|
||||
<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove" permission="app.admin.teacher.delete">
|
||||
<i class="layui-icon layui-icon-delete"></i>删除
|
||||
</button>
|
||||
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="import" permission="app.admin.teacher.insert">
|
||||
<i class="layui-icon layui-icon-upload"></i>批量导入账号
|
||||
</button>
|
||||
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="download_example" permission="app.admin.teacher.insert">
|
||||
<i class="layui-icon layui-icon-download-circle"></i>下载导入模板
|
||||
</button>
|
||||
</script>
|
||||
|
||||
<!-- 表格行工具栏 -->
|
||||
@ -96,12 +109,28 @@
|
||||
|
||||
// 相关常量
|
||||
const PRIMARY_KEY = "id";
|
||||
const SELECT_API = "/app/admin/teacher/select";
|
||||
const SELECT_API = "/app/admin/teacher/select?field=id&order=desc";
|
||||
const UPDATE_API = "/app/admin/teacher/update";
|
||||
const DELETE_API = "/app/admin/teacher/delete";
|
||||
const INSERT_URL = "/app/admin/teacher/insert";
|
||||
const UPDATE_URL = "/app/admin/teacher/update";
|
||||
|
||||
// 字段 头像 avatar
|
||||
layui.use(["upload", "layer"], function() {
|
||||
layui.upload.render({
|
||||
elem: "#upload_teacher_info",
|
||||
accept: 'file', //普通文件
|
||||
acceptMime: ".xls,.xlsx",
|
||||
url: "/app/admin/teacher/importTeacherAccount",
|
||||
field: "file",
|
||||
done: function (res) {
|
||||
layer.alert(res.msg, {icon: 1}, function(index){
|
||||
layer.close(index);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 表格渲染
|
||||
layui.use(["table", "form", "common", "popup", "util"], function() {
|
||||
let table = layui.table;
|
||||
@ -205,6 +234,19 @@
|
||||
add();
|
||||
} else if (obj.event === "refresh") {
|
||||
refreshTable();
|
||||
} else if (obj.event === "import") {
|
||||
import_file();
|
||||
} else if (obj.event === "download_example") {
|
||||
const link = document.createElement('a');
|
||||
link.style.display = 'none';
|
||||
// 设置下载地址
|
||||
link.setAttribute('href', '{$import_example}');
|
||||
// 设置文件名
|
||||
link.setAttribute('download', '{$example_name}');
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
// window.location.href = '{$import_example}';
|
||||
} else if (obj.event === "batchRemove") {
|
||||
batchRemove(obj);
|
||||
}
|
||||
@ -261,6 +303,10 @@
|
||||
content: INSERT_URL
|
||||
});
|
||||
}
|
||||
// 表格新增数据
|
||||
let import_file = function() {
|
||||
$('#upload_teacher_info').click();
|
||||
}
|
||||
|
||||
// 表格编辑数据
|
||||
let edit = function(obj) {
|
||||
|
BIN
public/files/xlsx/202408/2024080321300720.xlsx
Normal file
BIN
public/files/xlsx/202408/2024080321300720.xlsx
Normal file
Binary file not shown.
BIN
public/files/xlsx/202408/2024080321310480.xlsx
Normal file
BIN
public/files/xlsx/202408/2024080321310480.xlsx
Normal file
Binary file not shown.
BIN
public/files/xlsx/202408/2024080322190737.xlsx
Normal file
BIN
public/files/xlsx/202408/2024080322190737.xlsx
Normal file
Binary file not shown.
BIN
public/files/xlsx/202408/2024080322192257.xlsx
Normal file
BIN
public/files/xlsx/202408/2024080322192257.xlsx
Normal file
Binary file not shown.
BIN
public/files/xlsx/202408/2024080322262287.xlsx
Normal file
BIN
public/files/xlsx/202408/2024080322262287.xlsx
Normal file
Binary file not shown.
BIN
public/files/xlsx/202408/2024080322430185.xlsx
Normal file
BIN
public/files/xlsx/202408/2024080322430185.xlsx
Normal file
Binary file not shown.
BIN
public/files/xlsx/202408/2024080322432347.xlsx
Normal file
BIN
public/files/xlsx/202408/2024080322432347.xlsx
Normal file
Binary file not shown.
BIN
public/files/xlsx/202408/2024080322443396.xlsx
Normal file
BIN
public/files/xlsx/202408/2024080322443396.xlsx
Normal file
Binary file not shown.
BIN
public/files/xlsx/202408/2024080322452117.xlsx
Normal file
BIN
public/files/xlsx/202408/2024080322452117.xlsx
Normal file
Binary file not shown.
BIN
public/files/xlsx/202408/2024080322474292.xlsx
Normal file
BIN
public/files/xlsx/202408/2024080322474292.xlsx
Normal file
Binary file not shown.
BIN
public/files/xlsx/202408/2024080322582760.xlsx
Normal file
BIN
public/files/xlsx/202408/2024080322582760.xlsx
Normal file
Binary file not shown.
BIN
public/files/xlsx/202408/2024080322593187.xlsx
Normal file
BIN
public/files/xlsx/202408/2024080322593187.xlsx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user