Diy.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\diy;
  12. use app\dict\diy\PagesDict;
  13. use app\service\admin\diy\DiyService;
  14. use core\base\BaseAdminController;
  15. use Exception;
  16. use think\db\exception\DataNotFoundException;
  17. use think\db\exception\DbException;
  18. use think\db\exception\ModelNotFoundException;
  19. use think\Response;
  20. /**
  21. * 自定义页面控制器
  22. * Class DiyController
  23. * @package app\adminapi\controller\diy
  24. */
  25. class Diy extends BaseAdminController
  26. {
  27. /**
  28. * @notes 获取自定义页面分页列表
  29. * @return Response
  30. */
  31. public function lists()
  32. {
  33. $data = $this->request->params([
  34. [ "title", "" ],
  35. [ "type", "" ],
  36. [ 'mode', '' ],
  37. [ 'addon_name', '' ]
  38. ]);
  39. return success(( new DiyService() )->getPage($data));
  40. }
  41. /**
  42. * @notes 获取自定义页面分页列表,轮播搜索组件用
  43. * @return Response
  44. */
  45. public function getPageByCarouselSearch()
  46. {
  47. $data = $this->request->params([]);
  48. return success(( new DiyService() )->getPageByCarouselSearch($data));
  49. }
  50. /**
  51. * @notes 获取自定义页面列表
  52. * @return Response
  53. * @throws DataNotFoundException
  54. * @throws DbException
  55. * @throws ModelNotFoundException
  56. */
  57. public function getList()
  58. {
  59. $data = $this->request->params([
  60. [ "title", "" ],
  61. [ "type", "" ],
  62. [ 'mode', '' ]
  63. ]);
  64. return success(( new DiyService() )->getList($data));
  65. }
  66. /**
  67. * 自定义页面详情
  68. * @param int $id
  69. * @return Response
  70. */
  71. public function info(int $id)
  72. {
  73. return success(( new DiyService() )->getInfo($id));
  74. }
  75. /**
  76. * 添加自定义页面
  77. * @return Response
  78. */
  79. public function add()
  80. {
  81. $data = $this->request->params([
  82. [ "page_title", "" ],
  83. [ "title", "" ],
  84. [ "name", "" ],
  85. [ "type", "" ],
  86. [ 'template', '' ],
  87. [ 'mode', 'diy' ], // 页面展示模式,diy:自定义,fixed:固定
  88. [ "value", "", false ],
  89. [ 'is_default', 0 ],
  90. [ 'is_change', '' ]
  91. ]);
  92. $this->validate($data, 'app\validate\diy\Diy.add');
  93. $id = ( new DiyService() )->add($data);
  94. return success('ADD_SUCCESS', [ 'id' => $id ]);
  95. }
  96. /**
  97. * 自定义页面编辑
  98. * @param $id
  99. * @return Response
  100. */
  101. public function edit($id)
  102. {
  103. $data = $this->request->params([
  104. [ "page_title", "" ],
  105. [ "title", "" ],
  106. [ "name", "" ],
  107. [ 'template', '' ],
  108. [ 'mode', 'diy' ], // 页面展示模式,diy:自定义,fixed:固定
  109. [ "value", "", false ],
  110. [ 'is_change', '' ]
  111. ]);
  112. $this->validate($data, 'app\validate\diy\Diy.edit');
  113. ( new DiyService() )->edit($id, $data);
  114. return success('MODIFY_SUCCESS');
  115. }
  116. /**
  117. * 自定义页面删除
  118. * @param int $id
  119. * @return Response
  120. */
  121. public function del(int $id)
  122. {
  123. ( new DiyService() )->del($id);
  124. return success('DELETE_SUCCESS');
  125. }
  126. /**
  127. * 设为使用
  128. * @param $id
  129. * @return Response
  130. * @throws Exception
  131. */
  132. public function setUse($id)
  133. {
  134. ( new DiyService() )->setUse($id);
  135. return success('MODIFY_SUCCESS');
  136. }
  137. /**
  138. * 获取页面初始化数据
  139. * @return Response
  140. */
  141. public function getPageInit()
  142. {
  143. $params = $this->request->params([
  144. [ 'id', "" ],
  145. [ "name", "" ],
  146. [ "type", "" ],
  147. [ "title", "" ],
  148. ]);
  149. $diy_service = new DiyService();
  150. return success($diy_service->getInit($params));
  151. }
  152. /**
  153. * 获取自定义链接列表
  154. */
  155. public function getLink()
  156. {
  157. $diy_service = new DiyService();
  158. return success($diy_service->getLink());
  159. }
  160. /**
  161. * 获取页面模板
  162. * @return Response
  163. */
  164. public function getTemplate()
  165. {
  166. $params = $this->request->params([
  167. [ 'key', '' ], // 页面模板标识
  168. [ 'action', '' ], // 页面是否装修标识,为空标识不装修,decorate:装修
  169. [ 'mode', '' ], // 页面展示模式,diy:自定义,fixed:固定
  170. [ 'type', '' ], // 页面类型,index:首页、member_index:个人中心,空:普通页面
  171. [ 'addon', '' ], // 插件标识
  172. ]);
  173. $diy_service = new DiyService();
  174. return success($diy_service->getTemplate($params));
  175. }
  176. /**
  177. * 修改页面分享内容
  178. * @param int $id
  179. * @return Response
  180. */
  181. public function modifyShare(int $id)
  182. {
  183. $data = $this->request->params([
  184. [ "share", "" ],
  185. ]);
  186. ( new DiyService() )->modifyShare($id, $data);
  187. return success('MODIFY_SUCCESS');
  188. }
  189. /**
  190. * 获取装修页面列表
  191. */
  192. public function getDecoratePage()
  193. {
  194. $params = $this->request->params([
  195. [ 'type', '' ],
  196. ]);
  197. return success(( new DiyService() )->getDecoratePage($params));
  198. }
  199. /**
  200. * 切换模板
  201. */
  202. public function changeTemplate()
  203. {
  204. $data = $this->request->params([
  205. [ 'type', '' ], // 页面类型
  206. [ 'name', '' ], // 链接名称标识
  207. [ 'parent', '' ], // 链接父级名称标识
  208. [ 'page', '' ], // 链接路由
  209. [ 'title', '' ], // 链接标题
  210. [ 'action', '' ] // 是否存在操作,decorate 表示支持装修
  211. ]);
  212. ( new DiyService() )->changeTemplate($data);
  213. return success('MODIFY_SUCCESS');
  214. }
  215. /**
  216. * 获取模板页面列表
  217. * @return Response
  218. */
  219. public function getTemplatePages()
  220. {
  221. $params = $this->request->params([
  222. [ 'type', '' ], // 页面类型
  223. [ 'mode', '' ] // 页面模式:diy:自定义,fixed:固定
  224. ]);
  225. $pages = PagesDict::getPages($params);
  226. return success($pages);
  227. }
  228. /**
  229. * 获取模板页面(存在的应用插件列表)
  230. * @return Response
  231. */
  232. public function getApps()
  233. {
  234. return success(( new DiyService() )->getApps());
  235. }
  236. /**
  237. * 获取主题风格列表
  238. * @return Response
  239. */
  240. public function getDiyTheme()
  241. {
  242. return success(( new DiyService() )->getDiyTheme());
  243. }
  244. /**
  245. * 设置主题风格
  246. * @return Response
  247. */
  248. public function setDiyTheme()
  249. {
  250. $data = $this->request->params([
  251. [ 'id', '' ],
  252. [ 'addon', '' ],
  253. [ 'title', '' ],
  254. [ 'theme', '' ],
  255. [ 'new_theme', '' ],
  256. ]);
  257. ( new DiyService() )->setDiyTheme($data);
  258. return success('ADD_SUCCESS');
  259. }
  260. /**
  261. * 获取主题配色列表
  262. * @return Response
  263. */
  264. public function getDefaultThemeColor()
  265. {
  266. $data = $this->request->params([
  267. [ 'addon', '' ],
  268. ]);
  269. return success(( new DiyService() )->getDefaultThemeColor($data));
  270. }
  271. /**
  272. * 添加自定义主题配色
  273. * @return Response
  274. */
  275. public function addDiyTheme()
  276. {
  277. $data = $this->request->params([
  278. [ 'title', '' ],
  279. [ 'default_theme', '' ],
  280. [ 'theme', '' ],
  281. [ 'new_theme', '' ],
  282. [ 'addon', '' ]
  283. ]);
  284. $this->validate($data, 'app\validate\diy\DiyTheme.add');
  285. ( new DiyService() )->addDiyTheme($data);
  286. return success('ADD_SUCCESS');
  287. }
  288. /**
  289. * 编辑自定义主题配色
  290. * @param $id
  291. * @return Response
  292. */
  293. public function editDiyTheme($id)
  294. {
  295. $data = $this->request->params([
  296. [ 'title', '' ],
  297. [ 'theme', '' ],
  298. [ 'new_theme', '' ],
  299. [ 'addon', '' ]
  300. ]);
  301. $data[ 'id' ] = $id;
  302. $this->validate($data, 'app\validate\diy\DiyTheme.edit');
  303. ( new DiyService() )->editDiyTheme($id, $data);
  304. return success('EDIT_SUCCESS');
  305. }
  306. /**
  307. * 删除自定义主题配色
  308. * @param $id
  309. * @return Response
  310. */
  311. public function delDiyTheme(int $id)
  312. {
  313. ( new DiyService() )->delDiyTheme($id);
  314. return success('DELETE_SUCCESS');
  315. }
  316. }