Common.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <?php namespace Manage\Lib;
  2. use Dever;
  3. use Dever\Helper\Str;
  4. use Dever\Helper\Env;
  5. use Dever\Helper\Secure;
  6. class Common
  7. {
  8. public function auth()
  9. {
  10. $auth = Env::header('authorization');
  11. if ($auth) {
  12. $auth = ltrim($auth, 'Bearer ');
  13. Dever::session('auth', $auth);
  14. $info = Secure::checkLogin($auth);
  15. return $info;
  16. }
  17. return false;
  18. }
  19. # 获取当前使用的系统
  20. public function system($key = '')
  21. {
  22. $info = $this->auth();
  23. if (!$info) {
  24. $auth = Dever::session('auth');
  25. if (!$auth) {
  26. return false;
  27. }
  28. $info = Secure::checkLogin($auth);
  29. }
  30. if ($info && isset($info['extend']) && isset($info['extend']['relation_id'])) {
  31. # 这里后续增加从数据库中获取
  32. $value = $info['extend']['system_id'] . '_' . $info['extend']['relation_id'];
  33. if ($key) {
  34. return array($key => $value);
  35. }
  36. return $value;
  37. }
  38. return false;
  39. }
  40. # 生成token
  41. public function token($uid, $mobile, $system_id, $relation_id)
  42. {
  43. $extand['system_id'] = $system_id;
  44. $extand['relation_id'] = $relation_id;
  45. /* 暂时不做到库中
  46. $select['mobile'] = $mobile;
  47. $info = Dever::db('mobile_system')->find($select);
  48. $select += $extand;
  49. if (!$info) {
  50. Dever::db('mobile_system')->insert($select);
  51. } else {
  52. Dever::db('mobile_system')->update($info['id'], $select);
  53. }*/
  54. return array('token' => Secure::login($uid, $extand));
  55. }
  56. public function createPwd($password)
  57. {
  58. $data['salt'] = Str::salt(8);
  59. $data['password'] = $this->hash($password, $data['salt']);
  60. return $data;
  61. }
  62. public function hash($password, $salt)
  63. {
  64. return hash('sha256', $password . $salt);
  65. }
  66. # 仅为测试用
  67. public function out($data)
  68. {
  69. $result = array();
  70. $result['head'] = array('id', '姓名', '时间');
  71. $result['body'] = array();
  72. foreach ($data['body'] as $k => $v) {
  73. $result['body'][$k] = array($v['id'], $v['name'], $v['cdate']);
  74. }
  75. return $result;
  76. }
  77. # 仅为测试用,展示表格更多内容
  78. public function show($data)
  79. {
  80. # 返回类型:string字符串,table表格,list列表
  81. $result['type'] = 'string';
  82. $result['content'] = 'ddddd';
  83. $result['type'] = 'table';
  84. $result['head'] = array('id' => 'id', 'name' => '姓名');
  85. $result['body'] = array
  86. (
  87. array('id' => '1', 'name' => 'test'),
  88. array('id' => '2', 'name' => 'test2'),
  89. );
  90. $result['type'] = 'list';
  91. $result['content'] = array
  92. (
  93. array('日志类型', 'test'),
  94. array('姓名', 'test1'),
  95. );
  96. return $result;
  97. }
  98. # 仅为测试用,展示详情
  99. public function view($page)
  100. {
  101. # 这里获取基本信息
  102. //print_r($page->info);die;
  103. $info[] = array
  104. (
  105. # 类型,desc描述 table表格,表格有head和body即可
  106. 'type' => 'desc',
  107. 'name' => '基本信息',
  108. # 每行展示数量
  109. 'column' => 4,
  110. # 是否有边框
  111. 'border' => true,
  112. # 排列方向:horizontal横向 vertical纵向
  113. 'direction' => 'vertical',
  114. # 右侧按钮
  115. 'button' => array
  116. (
  117. array
  118. (
  119. 'name' => '编辑',
  120. # fastedit、fastadd、oper、api四个按钮类型,参数与list里的data_button一致,多了一个load,可以单独设置路由
  121. 'type' => 'fastedit',
  122. 'load' => 'platform/role',
  123. # 增加权限,第三个参数是排序,建议大一些
  124. //'func' => $page->getFunc('view_fastedit', '详情页-编辑角色', 1000),
  125. # 这里是按钮用到的参数数据
  126. 'row' => array
  127. (
  128. 'id' => 1,
  129. ),
  130. ),
  131. ),
  132. # 具体内容
  133. 'content' => array
  134. (
  135. array
  136. (
  137. 'name' => '标题',
  138. # 类型,text普通文本,tag标签,link链接,image图片 progress进度条 stat统计 timeline时间线 table表格
  139. 'type' => 'text',
  140. 'content' => '内容',
  141. # 样式primary success warning danger info exception
  142. 'style' => 'primary',
  143. ),
  144. array
  145. (
  146. 'name' => '标题',
  147. 'type' => 'tag',
  148. 'content' => '内容',
  149. 'style' => 'warning',
  150. ),
  151. array
  152. (
  153. 'name' => '标题',
  154. 'type' => 'link',
  155. 'content' => '内容',
  156. ),
  157. array
  158. (
  159. 'name' => '图片',
  160. 'type' => 'image',
  161. 'content' => 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
  162. # 'fill', 'contain', 'cover', 'none', 'scale-down'
  163. 'fit' => 'fill',
  164. ),
  165. array
  166. (
  167. 'name' => '进度条',
  168. 'type' => 'progress',
  169. 'content' => '10',
  170. 'style' => 'exception',
  171. 'width' => '20',
  172. 'inside' => true,
  173. # line dashboard 仪表盘 circle 圆形
  174. 'show' => 'line',
  175. # 开启条纹
  176. 'striped' => true,
  177. # 开启动画
  178. 'indeterminate' => true,
  179. ),
  180. array
  181. (
  182. 'name' => '统计',
  183. 'type' => 'stat',
  184. 'content' => array
  185. (
  186. array
  187. (
  188. # 一共24
  189. 'span' => '6',
  190. 'name' => '测试',
  191. 'value' => '1000',
  192. ),
  193. array
  194. (
  195. 'span' => '6',
  196. 'name' => '测试1',
  197. 'value' => '1000',
  198. ),
  199. array
  200. (
  201. 'span' => '6',
  202. 'name' => '测试2',
  203. 'value' => '1000',
  204. ),
  205. array
  206. (
  207. 'span' => '6',
  208. 'name' => '测试2',
  209. 'value' => '1000',
  210. ),
  211. ),
  212. ),
  213. array
  214. (
  215. 'name' => '时间线',
  216. 'type' => 'timeline',
  217. 'content' => array
  218. (
  219. array
  220. (
  221. 'time' => '2020-10-11',
  222. 'name' => '测试',
  223. 'color' => '#0bbd87',
  224. 'size' => 'large',
  225. 'type' => 'primary',
  226. 'hollow' => true,
  227. ),
  228. array
  229. (
  230. 'time' => '2020-10-11',
  231. 'name' => '测试',
  232. ),
  233. array
  234. (
  235. 'time' => '2020-10-11',
  236. 'name' => '测试',
  237. ),
  238. array
  239. (
  240. 'time' => '2020-10-11',
  241. 'name' => '测试',
  242. ),
  243. ),
  244. ),
  245. array
  246. (
  247. 'name' => '表格',
  248. 'type' => 'table',
  249. 'border' => true,
  250. 'height' => '200',
  251. 'head' => array
  252. (
  253. array
  254. (
  255. 'key' => 'name',
  256. 'name' => '姓名',
  257. 'fixed' => 'fixed',
  258. ),
  259. array
  260. (
  261. 'key' => 'desc',
  262. 'name' => '描述',
  263. 'fixed' => 'fixed',
  264. ),
  265. ),
  266. 'button' => array
  267. (
  268. array
  269. (
  270. 'name' => '编辑',
  271. 'type' => 'fastedit',
  272. 'load' => 'platform/role',
  273. ),
  274. ),
  275. 'body' => array
  276. (
  277. array
  278. (
  279. 'id' => 1,
  280. 'name' => 'test',
  281. 'desc' => 'dfdf',
  282. ),
  283. ),
  284. ),
  285. ),
  286. );
  287. $info[] = array
  288. (
  289. 'type' => 'table',
  290. 'name' => '表格信息',
  291. 'border' => true,
  292. 'height' => '200',
  293. 'head' => array
  294. (
  295. array
  296. (
  297. 'key' => 'name',
  298. 'name' => '姓名',
  299. 'fixed' => 'fixed',
  300. ),
  301. array
  302. (
  303. 'key' => 'desc',
  304. 'name' => '描述',
  305. 'fixed' => 'fixed',
  306. ),
  307. ),
  308. 'button' => array
  309. (
  310. array
  311. (
  312. 'name' => '编辑',
  313. 'type' => 'fastedit',
  314. 'load' => 'platform/role',
  315. # 增加权限,第三个参数是排序,建议大一些
  316. 'func' => $page->getFunc('view_fastedit', '详情页-编辑角色', 1000),
  317. ),
  318. ),
  319. 'body' => array
  320. (
  321. array
  322. (
  323. 'id' => 1,
  324. 'name' => 'test',
  325. 'desc' => 'dfdf',
  326. ),
  327. ),
  328. );
  329. $tab = array
  330. (
  331. 'active' => 'table1',
  332. 'content' => array
  333. (
  334. 'table1' => array
  335. (
  336. # 这里跟desc一样
  337. 'name' => '标题',
  338. 'type' => 'text',
  339. 'content' => '内容',
  340. 'style' => 'primary',
  341. ),
  342. 'tab2' => array
  343. (
  344. 'name' => '表格',
  345. 'type' => 'table',
  346. 'border' => true,
  347. 'height' => '200',
  348. 'head' => array
  349. (
  350. array
  351. (
  352. 'key' => 'name',
  353. 'name' => '姓名',
  354. 'fixed' => 'fixed',
  355. ),
  356. array
  357. (
  358. 'key' => 'desc',
  359. 'name' => '描述',
  360. 'fixed' => 'fixed',
  361. ),
  362. ),
  363. 'button' => array
  364. (
  365. array
  366. (
  367. 'name' => '编辑',
  368. 'type' => 'fastedit',
  369. 'load' => 'platform/role',
  370. ),
  371. ),
  372. 'body' => array
  373. (
  374. array
  375. (
  376. 'id' => 1,
  377. 'name' => 'test',
  378. 'desc' => 'dfdf',
  379. ),
  380. ),
  381. ),
  382. )
  383. );
  384. return array('info' => $info, 'tab' => $tab);
  385. }
  386. public function stat($where)
  387. {
  388. return array
  389. (
  390. array
  391. (
  392. # 一共24
  393. 'span' => '8',
  394. 'name' => '测试',
  395. 'value' => '1000',
  396. ),
  397. array
  398. (
  399. 'span' => '8',
  400. 'name' => '测试1',
  401. 'value' => '1000',
  402. ),
  403. array
  404. (
  405. 'span' => '8',
  406. 'name' => '测试2',
  407. 'value' => '1000',
  408. ),
  409. );
  410. }
  411. }