-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcms.php
88 lines (72 loc) · 2.48 KB
/
cms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
use League\Plates\Engine;
use PhpOffice\PhpSpreadsheet\IOFactory;
require_once 'init.php';
// --------------------------------------------------
// 获取项目
// --------------------------------------------------
if ($argc < 2) {
die('Usage: php index.php <PROJECT_NAME> [<TABLE_NAME>]' . "\n");
} else {
$project = $argv[1];
$excelFile = dirname(__FILE__) . '/projects/' . $argv[1] . '.xlsx';
if (!file_exists($excelFile)) {
die('Excel 文件 ' . $argv[1] . " 不存在!\n");
}
}
// --------------------------------------------------
// 获取实体
// --------------------------------------------------
try {
$spreadsheet = IOFactory::load($excelFile);
$rows = $spreadsheet->getActiveSheet()
->toArray(null, true, true, true);
} catch (\PhpOffice\PhpSpreadsheet\Reader\Exception $e) {
_e($e->getMessage());
} catch (\PhpOffice\PhpSpreadsheet\Exception $e) {
_e($e->getMessage());
}
$tables = [];
for ($i = 0; $i < count($rows); $i++) {
$row = $rows[$i];
if (is_null($row['B'])) {
continue;
}
if ($row['B'] == 'Table') { // 表开始
$table = [];
$table['tableName'] = $row['C'];
$table['tableNameCn'] = $row['D'];
$i += 2;
for (; $i < count($rows); $i++) {
$row = $rows[$i];
if (is_null($row['B'])) { // 表结束
$tables[] = $table;
break;
} else { // 表字段
$tbCol = [
'col' => trim($row['B']),
'colCn' => trim($row['C']),
'type' => trim($row['D']),
'len' => trim($row['E']),
'key' => trim($row['F']),
'form' => trim($row['H']),
'list' => trim($row['I']),
];
$table['cols'][] = $tbCol;
}
}
}
}
// --------------------------------------------------
// 生成模板
// --------------------------------------------------
foreach ($tables as $table) {
$plate = new Engine(dirname(__FILE__));
$plate->addData(['mark' => '?']);
$html = $plate->render('form', $table);
file_put_contents(dirname(__FILE__) . '/templates/' . $table['tableName'] . '_edit.html', $html);
$plate = new Engine(dirname(__FILE__));
$plate->addData(['mark' => '?']);
$html = $plate->render('list', $table);
file_put_contents(dirname(__FILE__) . '/templates/' . $table['tableName'] . '_list.html', $html);
}