Notice.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace modules\notice;
  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 Notice
  12. {
  13. private $uid = 'notice';
  14. public function install()
  15. {
  16. $pMenu = MenuRule::where('name', 'routine')->value('id');
  17. $menu = [
  18. [
  19. 'type' => 'menu',
  20. 'title' => '通知公告管理',
  21. 'name' => 'routine/notice',
  22. 'path' => 'routine/notice',
  23. 'icon' => 'el-icon-ChatLineRound',
  24. 'menu_type' => 'tab',
  25. 'component' => '/src/views/backend/routine/notice/index.vue',
  26. 'keepalive' => '1',
  27. 'pid' => $pMenu ? $pMenu : 0,
  28. 'children' => [
  29. ['type' => 'button', 'title' => '查看', 'name' => 'routine/notice/index'],
  30. ['type' => 'button', 'title' => '添加', 'name' => 'routine/notice/add'],
  31. ['type' => 'button', 'title' => '编辑', 'name' => 'routine/notice/edit'],
  32. ['type' => 'button', 'title' => '删除', 'name' => 'routine/notice/del'],
  33. ['type' => 'button', 'title' => '快速排序', 'name' => 'routine/notice/sortable'],
  34. ],
  35. ]
  36. ];
  37. Menu::create($menu);
  38. }
  39. public function uninstall()
  40. {
  41. Menu::delete('routine/notice', true);
  42. }
  43. public function enable()
  44. {
  45. Menu::enable('routine/notice');
  46. }
  47. public function disable()
  48. {
  49. Menu::disable('routine/notice');
  50. }
  51. public function update()
  52. {
  53. // 兼容系统v1.1.2的语言包按需加载
  54. // 寻找安装时备份中的lang/pages文件,如果有,还原到lang/backend内而不是原位置
  55. $ebakDir = root_path() . 'modules' . DIRECTORY_SEPARATOR . 'ebak' . DIRECTORY_SEPARATOR;
  56. $zipFile = $ebakDir . $this->uid . '-install.zip';
  57. $zipDir = false;
  58. if (is_file($zipFile)) {
  59. try {
  60. $zipDir = Server::unzip($zipFile);
  61. } catch (moduleException|Exception $e) {
  62. // skip
  63. }
  64. }
  65. if ($zipDir) {
  66. $oldBaInputs = [
  67. path_transform('web\src\lang\pages\zh-cn\routine\notice.ts'),
  68. path_transform('web\src\lang\pages\en\routine\notice.ts')
  69. ];
  70. foreach ($oldBaInputs as $oldBaInput) {
  71. @unlink(root_path() . $oldBaInput);
  72. }
  73. foreach (
  74. $iterator = new RecursiveIteratorIterator(
  75. new RecursiveDirectoryIterator($zipDir, FilesystemIterator::SKIP_DOTS),
  76. RecursiveIteratorIterator::SELF_FIRST
  77. ) as $item
  78. ) {
  79. $ebakFile = path_transform($iterator->getSubPathName());
  80. if (!$item->isDir() && in_array($ebakFile, $oldBaInputs)) {
  81. $newFileName = str_replace(DIRECTORY_SEPARATOR . 'pages' . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR . 'backend' . DIRECTORY_SEPARATOR, $ebakFile);
  82. copy($item, root_path() . $newFileName);
  83. }
  84. }
  85. }
  86. deldir($zipDir);
  87. del_empty_dir(root_path() . 'web/src/lang/pages/en');
  88. del_empty_dir(root_path() . 'web/src/lang/pages/zh-cn');
  89. }
  90. }