project.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?php
  2. # 定义几个常用的选项
  3. $local = array
  4. (
  5. 1 => '关闭',
  6. 2 => '开启',
  7. );
  8. $status = array
  9. (
  10. 1 => '未开始',
  11. 2 => '已完成',
  12. 3 => '队列中',
  13. 4 => '运行中',
  14. );
  15. $project = function()
  16. {
  17. $array = array
  18. (
  19. -1 => array('id' => '-1', 'name' => '父级项目'),
  20. );
  21. $info = Dever::load('spider/project-main');
  22. if ($info) {
  23. $array += $info;
  24. }
  25. return $array;
  26. };
  27. $info = Dever::load('manage/project.get');
  28. $path = $info['spider']['path'];
  29. if(isset($info['spider']['setup']))
  30. {
  31. $path = $info['spider']['setup'];
  32. }
  33. $id = Dever::input('option_pid', -1);
  34. return array
  35. (
  36. # 表名
  37. 'name' => 'project',
  38. # 显示给用户看的名称
  39. 'lang' => '项目管理',
  40. 'status' => $status,
  41. 'path' => $path,
  42. # 后台菜单排序
  43. 'order' => 20,
  44. 'desc' => Dever::markdown('**启动守护进程的方法:**
  45. 常规任务:请将 ```* * * * * root php '.$path.'daemon/main.php``` 放到crontab中[建议每分钟执行一次]'),
  46. # 数据结构
  47. 'struct' => array
  48. (
  49. 'id' => array
  50. (
  51. 'type' => 'int-11',
  52. 'name' => '项目ID',
  53. 'default' => '',
  54. 'desc' => '',
  55. 'match' => 'is_numeric',
  56. 'search' => 'order',
  57. //'list' => true,
  58. 'order' => 'desc',
  59. ),
  60. 'name' => array
  61. (
  62. 'type' => 'varchar-100',
  63. 'name' => '项目名称',
  64. 'default' => '',
  65. 'desc' => '请输入项目名称',
  66. 'match' => 'is_string',
  67. 'update' => 'text',
  68. 'search' => 'order,fulltext',
  69. 'list' => true,
  70. 'edit' => true,
  71. ),
  72. 'project_id' => array
  73. (
  74. 'type' => 'int-11',
  75. 'name' => '上级项目',
  76. 'default' => $id,
  77. 'desc' => '请选择上级分类',
  78. 'match' => 'is_numeric',
  79. 'update' => 'select',
  80. 'search' => 'select',
  81. 'option' => $project,
  82. ),
  83. 'site' => array
  84. (
  85. 'type' => 'text-255',
  86. 'name' => '采集网址-如有分页,请写成这样{page=1}',
  87. 'default' => '',
  88. 'desc' => '采集网址',
  89. 'match' => 'is_string',
  90. 'update' => $id < 0 ? 'hidden': 'textarea',
  91. //'list' => true,
  92. //'edit' => 'textarea',
  93. ),
  94. 'collect_rule' => array
  95. (
  96. 'type' => 'varchar-500',
  97. 'name' => '采集规则-为空则获取整个页面的内容,支持dom解析、json格式,如$(".info .title a").each().attr("href")',
  98. 'default' => '',
  99. 'desc' => '采集规则',
  100. 'match' => 'option',
  101. 'update' => $id < 0 ? 'hidden': 'textarea',
  102. //'edit' => true,
  103. //'list' => true,
  104. ),
  105. 'page_num' => array
  106. (
  107. 'type' => 'int-11',
  108. 'name' => '采集页数-值为0则默认采集100页',
  109. 'default' => '0',
  110. 'desc' => '采集页数',
  111. 'match' => 'option',
  112. 'update' => $id < 0 ? 'hidden': 'text',
  113. ),
  114. 'status' => array
  115. (
  116. 'type' => 'tinyint-1',
  117. 'name' => '状态',
  118. 'default' => '1',
  119. 'desc' => '状态',
  120. 'match' => 'is_numeric',
  121. 'option' => $status,
  122. 'list' => 'Dever::load("spider/lib/project.status", {id})',
  123. 'update' => 'radio',
  124. //'edit' => true,
  125. ),
  126. 'num' => array
  127. (
  128. 'type' => 'int-11',
  129. 'name' => '采集次数',
  130. 'default' => '0',
  131. 'desc' => '采集次数',
  132. 'match' => 'is_numeric',
  133. ),
  134. 'cur_page' => array
  135. (
  136. 'type' => 'int-11',
  137. 'name' => '当前采集页数',
  138. 'default' => '0',
  139. 'desc' => '当前采集页数',
  140. 'match' => 'is_numeric',
  141. ),
  142. 'sdate' => array
  143. (
  144. 'type' => 'int-11',
  145. 'name' => '下次采集时间',
  146. 'default' => '0',
  147. 'desc' => '下次采集时间',
  148. 'match' => 'is_numeric',
  149. //'update' => $id < 0 ? 'hidden' : 'date',
  150. 'callback' => 'maketime',
  151. ),
  152. 'interval' => array
  153. (
  154. 'type' => 'int-11',
  155. 'name' => '采集间隔秒数-填写开始时间之后的间隔采集的秒数,为0则只采集一次',
  156. 'default' => '0',
  157. 'desc' => '采集间隔秒数',
  158. 'match' => 'is_numeric',
  159. 'update' => $id < 0 ? 'hidden' : 'text',
  160. ),
  161. 'reorder' => array
  162. (
  163. 'type' => 'int-11',
  164. 'name' => '排序(数值越大越靠前)',
  165. 'default' => '1',
  166. 'desc' => '请输入排序',
  167. 'match' => 'option',
  168. 'update' => 'text',
  169. 'search' => 'order',
  170. 'list_name' => '排序',
  171. 'list' => true,
  172. 'order' => 'desc',
  173. 'edit' => true,
  174. ),
  175. 'state' => array
  176. (
  177. 'type' => 'tinyint-1',
  178. 'name' => '状态',
  179. 'default' => '1',
  180. 'desc' => '请选择状态',
  181. 'match' => 'is_numeric',
  182. ),
  183. 'cdate' => array
  184. (
  185. 'type' => 'int-11',
  186. 'name' => '更新时间',
  187. 'match' => array('is_numeric', time()),
  188. 'desc' => '',
  189. # 只有insert时才生效
  190. //'insert' => true,
  191. //'list' => 'date("Y-m-d H:i:s", {cdate})',
  192. ),
  193. ),
  194. 'manage' => array
  195. (
  196. //'delete' => false,
  197. # 更新数据时,要显示的按钮,这里填写js脚本事件即可。保存当前数据可为固定参数:"save-data",复制数据为:copy-data
  198. 'update_button' => array
  199. (
  200. '提交保存' => 'save-data',
  201. '放弃保存' => "msg({status:1,msg:'yes'})",
  202. //'复制数据' => 'copy-data',
  203. ),
  204. # 不允许编辑
  205. //'edit' => false,
  206. # 列表页的类型
  207. 'list_type' => 'parent',
  208. # 可以删除
  209. 'list_button' => array
  210. (
  211. 'update' => array('编辑', '"project&option_pid={project_id}"'),
  212. 'list_data' => array('查看采集数据', '"data&search_option_pid={id}&oper_save_jump=project&oper_parent=project"', '{project_id} > 0'),
  213. 'delete' => '删除',
  214. 'br1' => array('<br /><br />'),
  215. 'add' => array('新增子项目', '"project&option_pid={id}&oper_parent=project&oper_save_jump=project"', '{project_id} == -1'),
  216. 'list_col' => array('设置采集字段', '"col&search_option_pid={id}&oper_parent=project"', '{project_id} > 0 && {status} <= 2'),
  217. 'list_col1' => array('设置自定义字段', '"set&search_option_pid={id}&oper_parent=project"', '{project_id} > 0 && {status} <= 2'),
  218. 'list_col2' => array('设置同步推送', '"push&search_option_pid={id}&oper_parent=project"', '{project_id} > 0 && {status} <= 2'),
  219. 'br2' => array('<br /><br />'),
  220. 'new' => array('测试采集', 'Dever::url("spider/lib/api.test?id={id}")', '{project_id} > 0'),
  221. 'oper1' => array('开始采集', 'Dever::url("spider/lib/api.add?id={id}")', '{project_id} > 0 && {status} <= 2'),
  222. ),
  223. ),
  224. # request 请求接口定义
  225. 'request' => array
  226. (
  227. # main 取所有主分类
  228. 'main' => array
  229. (
  230. 'where' => array
  231. (
  232. 'project_id' => -1,
  233. 'state' => 1,
  234. ),
  235. 'type' => 'all',
  236. 'order' => array
  237. (
  238. 'reorder' => 'desc',
  239. 'id' => 'desc',
  240. ),
  241. 'col' => '*|id',
  242. ),
  243. # 获取所有已完成,并且有时间间隔的数据,重新入队
  244. 'getAll' => array
  245. (
  246. 'option' => array
  247. (
  248. 'id' => 'yes',
  249. 'status' => 2,
  250. 'interval' => array('yes', '>='),
  251. 'sdate' => array('yes-sdate', '<='),
  252. 'state' => 1,
  253. ),
  254. 'type' => 'all',
  255. 'order' => array('id' => 'desc'),
  256. 'col' => '*',
  257. ),
  258. 'getOne' => array
  259. (
  260. 'option' => array
  261. (
  262. 'id' => 'yes',
  263. 'status' => array('yes'),
  264. 'sdate' => array('yes-sdate', '<='),
  265. 'state' => 1,
  266. ),
  267. 'type' => 'one',
  268. ),
  269. )
  270. );