Department.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace modules\department;
  3. use app\common\library\Menu;
  4. use app\admin\model\MenuRule;
  5. use ba\module\moduleException;
  6. use ba\module\Server;
  7. use FilesystemIterator;
  8. use RecursiveDirectoryIterator;
  9. use RecursiveIteratorIterator;
  10. use think\Exception;
  11. class Department
  12. {
  13. private $uid = 'department';
  14. public function install()
  15. {
  16. $pMenu = MenuRule::where('name', 'auth')->value('id');
  17. $newMenus = [
  18. [
  19. 'type' => 'menu',
  20. 'title' => '部门管理',
  21. 'name' => 'department/department',
  22. 'path' => 'department/department',
  23. 'icon' => 'fa fa-sitemap',
  24. 'menu_type' => 'tab',
  25. 'component' => '/src/views/backend/department/department/index.vue',
  26. 'keepalive' => '0',
  27. 'pid' => $pMenu ? $pMenu : 0,
  28. 'children' => [
  29. ['type' => 'button', 'title' => '查看', 'name' => 'department/department/index'],
  30. ['type' => 'button', 'title' => '添加', 'name' => 'department/department/add'],
  31. ['type' => 'button', 'title' => '编辑', 'name' => 'department/department/edit'],
  32. ['type' => 'button', 'title' => '删除', 'name' => 'department/department/del'],
  33. ['type' => 'button', 'title' => '快速排序', 'name' => 'department/department/sortable'],
  34. ],
  35. ],
  36. [
  37. 'type' => 'menu',
  38. 'title' => '岗位管理',
  39. 'name' => 'department/jobs',
  40. 'path' => 'department/jobs',
  41. 'icon' => 'fa fa-id-badge',
  42. 'menu_type' => 'tab',
  43. 'component' => '/src/views/backend/department/jobs/index.vue',
  44. 'keepalive' => '1',
  45. 'pid' => $pMenu ? $pMenu : 0,
  46. 'children' => [
  47. ['type' => 'button', 'title' => '查看', 'name' => 'department/jobs/index'],
  48. ['type' => 'button', 'title' => '添加', 'name' => 'department/jobs/add'],
  49. ['type' => 'button', 'title' => '编辑', 'name' => 'department/jobs/edit'],
  50. ['type' => 'button', 'title' => '删除', 'name' => 'department/jobs/del'],
  51. ['type' => 'button', 'title' => '快速排序', 'name' => 'department/jobs/sortable'],
  52. ],
  53. ]
  54. ];
  55. Menu::create($newMenus);
  56. }
  57. public function uninstall()
  58. {
  59. Menu::delete('department/department', true);
  60. Menu::delete('department/jobs', true);
  61. }
  62. public function enable()
  63. {
  64. Menu::enable('department/department');
  65. Menu::enable('department/jobs');
  66. }
  67. public function disable()
  68. {
  69. Menu::disable('department/department');
  70. Menu::disable('department/jobs');
  71. }
  72. public function update()
  73. {
  74. // 兼容系统v1.1.2的语言包按需加载
  75. // 寻找安装时备份中的lang/pages文件,如果有,还原到lang/backend内而不是原位置
  76. $ebakDir = root_path() . 'modules' . DIRECTORY_SEPARATOR . 'ebak' . DIRECTORY_SEPARATOR;
  77. $zipFile = $ebakDir . $this->uid . '-install.zip';
  78. $zipDir = false;
  79. if (is_file($zipFile)) {
  80. try {
  81. $zipDir = Server::unzip($zipFile);
  82. } catch (moduleException|Exception $e) {
  83. // skip
  84. }
  85. }
  86. if ($zipDir) {
  87. $oldBaInputs = [
  88. path_transform('web\src\lang\pages\zh-cn\department\department.ts'),
  89. path_transform('web\src\lang\pages\en\department\department.ts'),
  90. path_transform('web\src\lang\pages\zh-cn\department\jobs.ts'),
  91. path_transform('web\src\lang\pages\en\department\jobs.ts'),
  92. ];
  93. foreach ($oldBaInputs as $oldBaInput) {
  94. @unlink(root_path() . $oldBaInput);
  95. }
  96. foreach (
  97. $iterator = new RecursiveIteratorIterator(
  98. new RecursiveDirectoryIterator($zipDir, FilesystemIterator::SKIP_DOTS),
  99. RecursiveIteratorIterator::SELF_FIRST
  100. ) as $item
  101. ) {
  102. $ebakFile = path_transform($iterator->getSubPathName());
  103. if (!$item->isDir() && in_array($ebakFile, $oldBaInputs)) {
  104. $newFileName = str_replace(DIRECTORY_SEPARATOR . 'pages' . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR . 'backend' . DIRECTORY_SEPARATOR, $ebakFile);
  105. copy($item, root_path() . $newFileName);
  106. }
  107. }
  108. }
  109. deldir($zipDir);
  110. del_empty_dir(root_path() . 'web/src/lang/pages/en');
  111. del_empty_dir(root_path() . 'web/src/lang/pages/zh-cn');
  112. }
  113. }