view_common.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +---------------------------------------------------------------------
  9. // | Author: Dean <zxxjjforever@163.com>
  10. // +----------------------------------------------------------------------
  11. use cmf\view\Filter;
  12. use cmf\view\Index;
  13. use huo\model\menu\AdminMenuModel;
  14. use huolib\tool\StrUtils;
  15. function view_edit($url) {
  16. return Index::edit($url);
  17. }
  18. function view_delete($url) {
  19. return Index::delete($url);
  20. }
  21. function view_img($url, $width = '40') {
  22. $url = cmf_get_image_preview_url($url);
  23. return Index::img($url, $width);
  24. }
  25. function view_btn_ajax($url, $class = 'btn btn-xs btn-yellow js-ajax-dialog-btn') {
  26. return Index::linkDialog($url);
  27. }
  28. function view_btn($url) {
  29. return Index::img($url);
  30. }
  31. function view_copy($url, $class = '') {
  32. return Index::copy($url, $class);
  33. }
  34. function filter_button() {
  35. return Filter::button(['title' => lang('search'), 'type' => 'search']);
  36. }
  37. function filter_button_clear($url = '') {
  38. return Filter::button(['title' => lang('clear'), 'type' => 'clear', 'uri' => $url]);
  39. }
  40. function button_export() {
  41. return Index::exportData();
  42. }
  43. /**
  44. * 输出文本框
  45. *
  46. * @param string $name 字段名称
  47. * @param string $value 字段值
  48. * @param string $placeholder 字段提示
  49. *
  50. * @return:string
  51. */
  52. function filter_text($name, $value = '', $placeholder = '') {
  53. return Filter::text($name, $value, $placeholder);
  54. }
  55. /**
  56. * 设置游戏实名认证状态
  57. *
  58. * @param int $auth_status 实名认证状态1为关闭,2为开启强制,3为开启不强制
  59. *
  60. * @return:
  61. */
  62. function select_identify($auth_status) {
  63. return \huoIdentify\view\Index::selectIdentify($auth_status);
  64. }
  65. /**
  66. * 列表编辑操作
  67. *
  68. * @param string|int $id_or_url 传入ID或者链接
  69. *
  70. * @param bool $new_frame 是否弹框
  71. * @param int $width 弹框宽度
  72. * @param int $height 弹框高度
  73. *
  74. * @return string
  75. */
  76. function action_edit($id_or_url, $new_frame = false, $width = 800, $height = 500) {
  77. if (is_numeric($id_or_url)) {
  78. $_url = url('edit', ['id' => $id_or_url]);
  79. $_auth_url = request()->module().'/'.request()->controller().'/edit';
  80. } else {
  81. $_url = $id_or_url;
  82. $_auth_url = $id_or_url;
  83. $name = explode('/', $id_or_url);
  84. if (isset($name[3])) {
  85. $_auth_url = $name[1].'/'.$name[2].'/'.$name[3];
  86. }
  87. }
  88. $_auth = cmf_auth_check(cmf_get_current_admin_id(), $_auth_url);
  89. if (false == $_auth) {
  90. return '';
  91. }
  92. if ($new_frame) {
  93. return \cmf\view\Index::linkOpenIframeDialog(
  94. $_url, lang('EDIT'), '<span class="text-info"><i class="fa fa-pencil"></i></span>', $width, $height,
  95. 'btn-xs btn-link', lang('EDIT')
  96. );
  97. } else {
  98. return \cmf\view\Index::edit($_url);
  99. }
  100. }
  101. /**
  102. * 列表页新增入口
  103. *
  104. * @param string $lang_key 语言KEY
  105. * @param string $add_or_url 新增
  106. *
  107. * @param bool $new_frame 是否弹框
  108. * @param int $width 弹框宽度
  109. * @param int $height 弹框高度
  110. *
  111. * @return string
  112. */
  113. function action_add($lang_key, $add_or_url = '', $new_frame = true, $width = 800, $height = 500) {
  114. if (empty($add_or_url) || 'add' == $add_or_url) {
  115. $_url = url('add');
  116. $_auth_url = request()->module().'/'.request()->controller().'/add';
  117. } else {
  118. $_url = $add_or_url;
  119. $_auth_url = $add_or_url;
  120. }
  121. $_auth = cmf_auth_check(cmf_get_current_admin_id(), $_auth_url);
  122. if (false == $_auth) {
  123. return '';
  124. }
  125. if (empty($lang_key)) {
  126. $_lang = lang('ADD');
  127. } else {
  128. $_lang = lang($lang_key);
  129. }
  130. if (true == $_auth) {
  131. if (true == $new_frame) {
  132. return \cmf\view\Index::linkOpenIframeDialog(
  133. $_url, $_lang, '<i class="fa fa-plus"></i>'.$_lang, $width, $height, 'btn-success', $_lang
  134. );
  135. } else {
  136. return '<a class="btn btn-success" href="'.$_url.'"><i class="fa fa-plus"></i> '.$_lang.'</a>';
  137. }
  138. }
  139. return '';
  140. }
  141. /**
  142. * 列表删除操作
  143. *
  144. * @param string|int $id_or_url 传入ID或者链接
  145. *
  146. * @return string
  147. */
  148. function action_delete($id_or_url) {
  149. if (is_numeric($id_or_url)) {
  150. $_url = url('delete', ['id' => $id_or_url]);
  151. $_auth_url = request()->module().'/'.request()->controller().'/delete';
  152. } else {
  153. $_url = $id_or_url;
  154. $_auth_url = $id_or_url;
  155. }
  156. $_auth = cmf_auth_check(cmf_get_current_admin_id(), $_auth_url);
  157. if (false == $_auth) {
  158. return '';
  159. }
  160. return \cmf\view\Index::delete($_url);
  161. }
  162. /**
  163. * 列表状态操作
  164. *
  165. * @param $id_or_url
  166. * @param int $current_value 目前值
  167. * @param int $value 目标值
  168. * @param string $lang_key 变化的值
  169. * @param string $current_status_str 目前状态名称
  170. * @param string $name 字段
  171. * @param string $func 函数
  172. *
  173. * @return string
  174. */
  175. function action_status(
  176. $id_or_url, $current_value, $value, $lang_key, $current_status_str, $name = 'status', $func = 'setStatus'
  177. ) {
  178. if (is_numeric($id_or_url)) {
  179. $_url = url($func, ['id' => $id_or_url, $name => $value, 'field' => $name]);
  180. } else {
  181. $_url = $id_or_url;
  182. }
  183. $_auth = cmf_auth_check(cmf_get_current_admin_id(), $_url);
  184. if (false == $_auth) {
  185. return '';
  186. }
  187. switch ($current_value) {
  188. case 1:
  189. $_class = 'btn-default';
  190. break;
  191. case 2:
  192. $_class = 'btn-success';
  193. break;
  194. case 3:
  195. $_class = 'btn-primary';
  196. break;
  197. default:
  198. $_class = 'btn-info';
  199. break;
  200. }
  201. $_lang_key = $lang_key;
  202. $_target_status_str = lang($_lang_key);
  203. return \cmf\view\Index::link(
  204. $_url, '', '', 'btn btn-xs '.$_class.' js-ajax-dialog-btn',
  205. lang('CONFIRM').$_target_status_str.'?', $current_status_str, ''
  206. );
  207. }
  208. function view_param($param, $title = '') {
  209. if (empty($param)) {
  210. return '';
  211. }
  212. if (false == is_string($param)) {
  213. $param = json_encode($param);
  214. }
  215. $_title = $title;
  216. if (empty($title)) {
  217. $_title = mb_substr($param, 0, 50);
  218. if (strlen($_title) > 50) {
  219. $_title .= '...';
  220. }
  221. }
  222. $_html
  223. = <<<EOF
  224. <div class="action-buttons">
  225. {$title}
  226. <a href="javascript:;" data-toggle="tooltip" title='{$_title}' onclick="showParam(this)">
  227. <span class="text-success"><i class="fa fa-file-text"></i></span>
  228. <div class="content" style="display: none">{$param}</div>
  229. </a>
  230. </div>
  231. EOF;
  232. return $_html;
  233. }
  234. function view_sort($id, $list_order, $width = 100) {
  235. $_max_int = CommonConst::CONST_MAX_INT;
  236. $_html
  237. = <<<EOF
  238. <input name='list_orders[{$id}]'
  239. class="input input-order mr5" type='text' size='10'
  240. onkeyup="clearNoNum(this,0,$_max_int;)"
  241. onafterpaste="clearNoNum(this,0,$_max_int)"
  242. style="width: {$width}px;text-align: center;"
  243. value='{$list_order}'>
  244. EOF;
  245. return $_html;
  246. }
  247. function view_time($ts = 0, $format = 'Y-m-d H:i') {
  248. if (empty($ts)) {
  249. return '';
  250. }
  251. return date($format, $ts);
  252. }
  253. function date_search(
  254. $time_range, $func = 'index', $time_range_arr
  255. = ['today',
  256. 'yesterday',
  257. 'seven_days',
  258. 'this_week',
  259. 'last_week',
  260. 'this_month',
  261. 'last_month',
  262. 'thirty_days']
  263. ) {
  264. $_time_range_arr = $time_range_arr;
  265. $_html = '';
  266. foreach ($_time_range_arr as $_v) {
  267. $_btn = 'btn-default';
  268. if ($time_range == $_v) {
  269. $_btn = 'btn-success';
  270. }
  271. $_html .= '<a class="btn '.$_btn.'" href="'.url($func, ['time_range' => $_v]).'">'.lang(strtoupper($_v)).'</a>';
  272. }
  273. return $_html;
  274. }
  275. /**
  276. * 打开链接
  277. *
  278. * @param $url
  279. *
  280. * @return string
  281. */
  282. function view_link($url) {
  283. if (empty($url)) {
  284. return '';
  285. }
  286. $_html = cmf\view\Index::link($url, $url, 'chain', 'btn-xs btn-link', '', '', 'info', '', 'view_window');
  287. return $_html;
  288. }
  289. /**
  290. * 列表中游戏列表
  291. *
  292. * @param string $url 请求地址
  293. * @param bool $new_frame 是否Frame打开
  294. * @param string $lang_key
  295. *
  296. * @param int $width
  297. * @param int $height
  298. *
  299. * @return string
  300. */
  301. function view_game($url, $new_frame = true, $lang_key = 'GAME_LIST', $width = 1000, $height = 600) {
  302. if (empty($url)) {
  303. return '';
  304. }
  305. if ($new_frame) {
  306. $_html = Index::linkOpenIframeDialog(
  307. $url, lang($lang_key), '<span class="text-info"><i class="fa fa-gamepad"></i></span>', $width, $height,
  308. 'btn-xs btn-link', lang($lang_key)
  309. );
  310. } else {
  311. $_html = cmf\view\Index::link($url, lang($lang_key), 'gamepad', '', lang($lang_key), '', 'info');
  312. }
  313. return $_html;
  314. }
  315. /**
  316. * 列表中渠道列表
  317. *
  318. * @param string $url 请求地址
  319. * @param bool $new_frame 是否Frame打开
  320. * @param string $lang_key
  321. *
  322. * @param int $width
  323. * @param int $height
  324. *
  325. * @return string
  326. */
  327. function view_channel($url, $new_frame = true, $lang_key = 'CHANNEL_LIST', $width = 1000, $height = 600) {
  328. if (empty($url)) {
  329. return '';
  330. }
  331. if ($new_frame) {
  332. $_html = Index::linkOpenIframeDialog(
  333. $url, lang($lang_key), '<span class="text-info"><i class="fa fa-sitemap"></i></span>', $width, $height,
  334. 'btn-xs btn-link', lang($lang_key)
  335. );
  336. } else {
  337. $_html = cmf\view\Index::link($url, lang($lang_key), 'fa-sitemap', '', lang($lang_key), '', 'info');
  338. }
  339. return $_html;
  340. }
  341. /**
  342. * 输出订单号文本框
  343. *
  344. * @param string $value 字段值
  345. * @param string $placeholder 字段提示
  346. *
  347. * @return:string
  348. */
  349. function filter_text_order_id($value = '', $placeholder = '') {
  350. $_placeholder = empty($placeholder) ? lang('MSG_ORDER_ID_INPUT') : $placeholder;
  351. return Filter::text('order_id', $value, $_placeholder);
  352. }
  353. /**
  354. * 输出玩家账号文本框
  355. *
  356. * @param string $value 字段值
  357. * @param string $placeholder 字段提示
  358. *
  359. * @return:string
  360. */
  361. function filter_text_username($value = '', $placeholder = '') {
  362. $_placeholder = empty($placeholder) ? lang('MSG_INPUT_ACCOUNT') : $placeholder;
  363. return Filter::text('username', $value, $_placeholder);
  364. }
  365. /**
  366. * 输出玩家注册手机号文本框
  367. *
  368. * @param string $value 字段值
  369. * @param string $placeholder 字段提示
  370. *
  371. * @return string
  372. */
  373. function filter_text_reg_mobile($value = '', $placeholder = '') {
  374. $_placeholder = empty($placeholder) ? lang('MSG_MEMBER_REG_MOBILE_INPUT') : $placeholder;
  375. return Filter::text('reg_mobile', $value, $_placeholder);
  376. }
  377. /**
  378. * @param string $info 提示信息
  379. * @param string $place 显示位置 默认底部
  380. *
  381. * @return string
  382. */
  383. function view_tips($info, $place = 'bottom') {
  384. return '<i class="iconfont tips icon-i" style="color: #a9a9a9;font-size: 10px;margin-right: 8px;" title="'.$info
  385. .'" data-toggle="tooltip" data-placement="'.$place.'"></i>';
  386. }
  387. /**
  388. * 跳转详情操作
  389. *
  390. * @param string|int $id_or_url 传入ID或者链接
  391. *
  392. * @param string $id_key
  393. *
  394. * @param bool $new_frame
  395. * @param int $width
  396. * @param int $height
  397. *
  398. * @return string
  399. */
  400. function action_detail($id_or_url, $id_key = 'id', $new_frame = false, $width = 1000, $height = 800) {
  401. if (substr_count($id_or_url, '/') < 3) {
  402. $_url = url('detail', [$id_key => $id_or_url]);
  403. } else {
  404. $_url = $id_or_url;
  405. }
  406. $_auth = cmf_auth_check(cmf_get_current_admin_id(), $_url);
  407. if (false == $_auth) {
  408. return '';
  409. }
  410. if ($new_frame) {
  411. return Index::linkOpenIframeDialog(
  412. $_url, lang('DETAIL'), '<span class="text-info"><i class="fa fa-eye"></i></span>', $width, $height,
  413. 'btn-xs btn-link', lang('EDIT')
  414. );
  415. } else {
  416. return action_link($_url, 'DETAIL', 'eye');
  417. }
  418. }
  419. /**
  420. * 跳转链接操作
  421. *
  422. * @param string $link 链接
  423. * @param string $lang_key 显示文字语言KEY
  424. * @param string $icon 图标
  425. *
  426. * @return: string
  427. */
  428. function action_link($link, $lang_key, $icon = '') {
  429. $_url = $link;
  430. $_auth = cmf_auth_check(cmf_get_current_admin_id(), $_url);
  431. if (false == $_auth) {
  432. return '';
  433. }
  434. $_title = lang($lang_key);
  435. return Index::link($_url, $_title, $icon);
  436. }
  437. /**
  438. * 确认操作(二次确认操作,用于更改数据状态等操作)
  439. *
  440. * @param string $link 链接
  441. * @param string $lang_key 显示文字语言KEY
  442. * @param string $msg_lang_key 提示文字语言KEY
  443. * @param string $type 类型,默认是btn
  444. * @param string $class ICON下面为图标样式,BUTTON下为按钮样式
  445. *
  446. * @return string
  447. */
  448. function action_confirm($link, $lang_key, $msg_lang_key, $type = 'btn', $class = '') {
  449. $_url = $link;
  450. $_auth = cmf_auth_check(cmf_get_current_admin_id(), $_url);
  451. if (false == $_auth) {
  452. return '';
  453. }
  454. $_title = lang($lang_key);
  455. $_msg = lang($msg_lang_key);
  456. switch ($type) {
  457. /*图标类型*/
  458. case 'icon':
  459. $_class = empty($class) ? 'edit' : $class;
  460. $_class = 'fa-'.$_class;
  461. $_html
  462. = <<<EOF
  463. <a href="{$_url}"
  464. title="{$_title}"
  465. data-toggle="tooltip"
  466. data-original-title="{$_title}"
  467. class="js-ajax-dialog-btn"
  468. data-msg="{$_msg}?">
  469. <span class="text-danger"><i class="fa {$_class}"></i></span>
  470. </a>
  471. EOF;
  472. break;
  473. /*按钮类型*/
  474. case 'btn':
  475. case 'button':
  476. $_class = empty($class) ? 'default' : $class;
  477. $_class = 'btn-'.$_class;
  478. $_html
  479. = <<<EOF
  480. <a href="{$_url}"
  481. title="{$_title}"
  482. data-toggle="tooltip"
  483. data-original-title="{$_title}"
  484. class="btn btn-xs {$_class} js-ajax-dialog-btn"
  485. data-msg="{$_msg}?">
  486. {$_title}
  487. </a>
  488. EOF;
  489. break;
  490. default:
  491. $_html = '';
  492. break;
  493. }
  494. return $_html;
  495. }
  496. /**
  497. * 弹框操作
  498. *
  499. * @param string $link 链接
  500. * @param string $lang_key 显示文字语言KEY
  501. * @param string $type 类型,默认是btn
  502. * @param string $class ICON下面为图标样式,BUTTON下为按钮样式
  503. * @param int $width
  504. * @param int $height
  505. * @param string $dialog_lang_key
  506. *
  507. * @return string :string
  508. */
  509. function action_dialog(
  510. $link, $lang_key, $type = 'btn', $class = '', $width = 800,
  511. $height = 400, $dialog_lang_key = ''
  512. ) {
  513. $_url = $link;
  514. $_auth = cmf_auth_check(cmf_get_current_admin_id(), $_url);
  515. if (false == $_auth) {
  516. return '';
  517. }
  518. $_title = lang($lang_key);
  519. $dialog_title = !empty($dialog_lang_key) ? lang($dialog_lang_key) : $_title;
  520. switch ($type) {
  521. /*图标类型*/
  522. case 'icon':
  523. $_class = empty($class) ? 'edit' : $class;
  524. $_class = 'fa-'.$_class;
  525. $_html
  526. = <<<EOF
  527. <a title="{$dialog_title}" data-toggle="tooltip" data-original-title="{$dialog_title}" href="javascript:openIframeDialog('{$link}','{$_title}',{width:'{$width}px',height:'{$height}px'});">
  528. <span class="text-info">
  529. <i class="fa {$_class}"></i>
  530. </span>
  531. </a>
  532. EOF;
  533. break;
  534. /*按钮类型*/
  535. case 'btn':
  536. case 'button':
  537. $_class = empty($class) ? 'default' : $class;
  538. $_class = 'btn-'.$_class;
  539. $_html = Index::linkOpenIframeDialog(
  540. $_url, $dialog_title, $_title, $width, $height, $_class, $_title
  541. );
  542. break;
  543. default:
  544. $_html = '';
  545. break;
  546. }
  547. return $_html;
  548. }
  549. /***
  550. * 列表审核操作
  551. *
  552. * @param $id
  553. * @param $value
  554. * @param $lang_key
  555. * @param string $name
  556. * @param string $func
  557. * @param string $original_title_key
  558. * @param string $id_name
  559. * @param string $fa
  560. * @param string $class
  561. *
  562. * @return string
  563. */
  564. function action_check(
  565. $id, $value, $lang_key, $name = 'status', $func = 'setStatus', $original_title_key = '', $id_name = 'id',
  566. $fa = 'check', $class = ''
  567. ) {
  568. $_auth_url = request()->module().'/'.request()->controller().'/'.$func;
  569. $_auth = cmf_auth_check(cmf_get_current_admin_id(), $_auth_url);
  570. if (false == $_auth) {
  571. return '';
  572. }
  573. $_url = url($_auth_url, [$id_name => $id, $name => $value]);
  574. $_lang_key = $lang_key;
  575. $_target_status_str = lang($_lang_key);
  576. $_original_title = '';
  577. if (!empty($original_title_key)) {
  578. $_original_title = lang($original_title_key);
  579. }
  580. return Index::link(
  581. $_url, $_original_title, '', $class.' js-ajax-dialog-btn',
  582. lang('CONFIRM').$_target_status_str.'?', '<span class="text-info"><i class="fa fa-'.$fa.'"></i></span>',
  583. ''
  584. );
  585. }
  586. /**
  587. * 列表删除操作
  588. *
  589. * @param string|int $id_or_url 传入ID或者链接
  590. *
  591. * @param bool $new_frame 是否弹框
  592. * @param int $width 弹框宽度
  593. * @param int $height 弹框高度
  594. *
  595. * @return string
  596. */
  597. function action_add_sub($id_or_url, $new_frame = false, $width = 800, $height = 500) {
  598. if (is_numeric($id_or_url)) {
  599. $_url = url('add', ['id' => $id_or_url]);
  600. } else {
  601. $_url = $id_or_url;
  602. }
  603. $_auth = cmf_auth_check(cmf_get_current_admin_id(), $_url);
  604. if (false == $_auth) {
  605. return '';
  606. }
  607. if ($new_frame) {
  608. return Index::linkOpenIframeDialog(
  609. $_url, lang('ADD'), '<span class="text-info"><i class="fa fa-plus"></i></span>', $width, $height,
  610. 'btn-xs btn-link', lang('ADD')
  611. );
  612. } else {
  613. return Index::edit($_url, lang('ADD'));
  614. }
  615. }
  616. /**
  617. * 输入数字限制
  618. *
  619. * @param string $name 名称
  620. * @param int $value 默认值
  621. * @param int $min 最小值
  622. * @param int $max 最大值
  623. * @param string $style 样式
  624. * @param string $required 是否必须
  625. *
  626. * @return string
  627. */
  628. function input_num(
  629. $name, $value = 0, $min = 0, $max = CommonConst::CONST_MAX_INT, $style = '', $required = '', $placeholder = ''
  630. ) {
  631. $_html = '<input class="input form-control" name="'.$name.'" id="'.$name.'"
  632. style="'.$style.'" '.$required.'
  633. onkeyup="clearNoNum(this,'.$min.','.$max.')"
  634. onafterpaste="clearNoNum(this,'.$min.','.$max.')"
  635. placeholder="'.$placeholder.'"
  636. value="'.$value.'">';
  637. return $_html;
  638. }
  639. /**
  640. * 输入数字与逗号
  641. *
  642. * @param string $name 名称
  643. * @param int $value 默认值
  644. *
  645. * @return string
  646. */
  647. function input_num_comma($name, $value = 0) {
  648. $_html = '<input class="input form-control" type="text" name="'.$name.'" id="'.$name.'"
  649. onkeyup="this.value=this.value.replace(/[^\d,]/g,\'\')"
  650. onafterpaste="this.value=this.value.replace(/[^\d,]/g,\'\')"
  651. value="'.$value.'" >';
  652. return $_html;
  653. }
  654. /**
  655. * 输入数字与点号
  656. *
  657. * @param string $name 名称
  658. * @param int $value 默认值
  659. *
  660. * @return string
  661. */
  662. function input_num_dot($name, $value = 0) {
  663. $_html = '<input class="input form-control" type="text" name="'.$name.'" id="'.$name.'"
  664. onkeyup="this.value=this.value.replace(/[^\d.]/g,\'\')"
  665. onafterpaste="this.value=this.value.replace(/[^\d.]/g,\'\')"
  666. value="'.$value.'" >';
  667. return $_html;
  668. }
  669. /**
  670. * 调用上传图片
  671. *
  672. * @param string $value 图片值
  673. * @param string $name 图片名
  674. * @param string $id 图片ID
  675. *
  676. * @return string
  677. */
  678. function upload_image($value = '', $name = 'image', $id = 'thumb') {
  679. $_static_site = STATICSITE;
  680. if (empty($value)) {
  681. $_img = "<img src='".STATICSITE."/admin/assets/images/default-thumbnail.png' id='".$id
  682. ."-preview' width='135' style='cursor: hand'/>";
  683. } else {
  684. $_img = "<img src='".cmf_get_image_preview_url($value)."' id='".$id
  685. ."-preview' width='135' style='cursor: hand'/>";
  686. }
  687. $_lang_image_upload = lang('IMAGE_UPLOAD');
  688. $_lang_image_cancel = lang('IMAGE_CANCEL');
  689. $_html
  690. = <<< EOT
  691. <input type="hidden" name="$name" id="$id" value="$value">
  692. <a href="javascript:uploadOneImage('{$_lang_image_upload}','#$id');">
  693. {$_img}
  694. </a>
  695. <input type="button" class="btn btn-sm btn-cancel-thumbnail"
  696. onclick="$('#{$id}-preview').attr('src','{$_static_site}/admin/assets/images/default-thumbnail.png');$('#{$id}').val('');return false;"
  697. value="{$_lang_image_cancel}">
  698. EOT;
  699. return $_html;
  700. }
  701. function action_url(
  702. $id_or_url, $new_frame = false, $logo = 'eye', $tip = 'edit', $info = 'info', $width = 800, $height = 500
  703. ) {
  704. if (is_numeric($id_or_url)) {
  705. $_url = url('edit', ['id' => $id_or_url]);
  706. $_auth_url = request()->module().'/'.request()->controller().'/edit';
  707. } else {
  708. $_url = $id_or_url;
  709. $_auth_url = $id_or_url;
  710. $name = explode('/', $id_or_url);
  711. if (isset($name[3])) {
  712. $_auth_url = $name[1].'/'.$name[2].'/'.$name[3];
  713. }
  714. }
  715. $_auth = cmf_auth_check(cmf_get_current_admin_id(), $_auth_url);
  716. if (false == $_auth) {
  717. return '';
  718. }
  719. if ($new_frame) {
  720. return \cmf\view\Index::linkOpenIframeDialog(
  721. $_url, $tip, '<span class="text-info"><i class="fa fa-pencil"></i></span>', $width, $height,
  722. 'btn-xs btn-link', $tip
  723. );
  724. } else {
  725. //return \cmf\view\Index::edit($_url);
  726. return cmf\view\Index::link($_url, $tip, $logo, '', $tip, '', $info);
  727. }
  728. }
  729. /**
  730. * 设置菜单
  731. *
  732. * @param int $parent_id
  733. * @param string $default_action
  734. * @param int $new_frame 是否返回上级页面
  735. *
  736. * @return string
  737. */
  738. function setting_menu($parent_id, $default_action = '', $new_frame = 1) {
  739. $_default_action = $default_action;
  740. if (empty($_default_action)) {
  741. $_default_action = request()->action();
  742. }
  743. $_menu_model = new AdminMenuModel();
  744. $_menu_data = $_menu_model->adminMenu($parent_id);
  745. $_txt = '';
  746. if (count($_menu_data) > 0) {
  747. $_txt = '<ul class="nav nav-tabs">';
  748. foreach ($_menu_data as $_menu) {
  749. $_name = $_menu['app'];
  750. $_controller = ucwords($_menu['controller']);
  751. $_action = $_menu['action'];
  752. //附带参数
  753. if ($_menu['param']) {
  754. $_params = "?".htmlspecialchars_decode($_menu['param']).'&new_frame='.$new_frame;
  755. } else {
  756. $_params = '?new_frame='.$new_frame;
  757. }
  758. $_url = url("{$_name}/{$_controller}/{$_action}{$_params}");
  759. $_lang = strtoupper($_name.'_'.$_controller.'_'.$_action);
  760. $_class = '';
  761. if (strtolower($_default_action) == strtolower($_action)) {
  762. $_class = 'active';
  763. }
  764. $_txt .= "<li class='{$_class}'> <a href='{$_url}'>".lang($_lang)."</a></li>";
  765. }
  766. $_txt .= "</ul>";
  767. }
  768. return $_txt;
  769. }
  770. function button($lang_key, $id, $class) {
  771. return Filter::button(['title' => lang($lang_key), 'type' => $id, 'class' => $class]);
  772. }
  773. /**
  774. * 列表状态标识
  775. *
  776. * @param int $current_value 目前值
  777. * @param string $current_status_str 目前状态名称
  778. *
  779. * @return string
  780. */
  781. function btn_status($current_value, $current_status_str) {
  782. switch ($current_value) {
  783. case 1:
  784. $_class = 'btn-default';
  785. break;
  786. case 2:
  787. $_class = 'btn-success';
  788. break;
  789. case 3:
  790. $_class = 'btn-primary';
  791. break;
  792. default:
  793. $_class = 'btn-info';
  794. break;
  795. }
  796. return Index::link(
  797. '#', '', '', 'btn btn-xs '.$_class,
  798. '', $current_status_str, ''
  799. );
  800. }
  801. function get_btn($value) {
  802. switch ($value) {
  803. case 1:
  804. $_class = 'danger';
  805. break;
  806. case 2:
  807. $_class = 'success';
  808. break;
  809. case 3:
  810. $_class = 'primary';
  811. break;
  812. case 4:
  813. $_class = 'warning';
  814. break;
  815. default:
  816. $_class = 'default';
  817. break;
  818. }
  819. return $_class;
  820. }
  821. function get_btn1($value) {
  822. switch ($value) {
  823. case 1:
  824. $_class = 'info';
  825. break;
  826. case 2:
  827. $_class = 'success';
  828. break;
  829. case 3:
  830. $_class = 'primary';
  831. break;
  832. case 4:
  833. $_class = 'warning';
  834. break;
  835. default:
  836. $_class = 'default';
  837. break;
  838. }
  839. return $_class;
  840. }
  841. /**
  842. * 列表删除操作
  843. *
  844. * @param int|string $id_or_url ID或者地址
  845. * @param int $current_value 目前值
  846. * @param int $value 目标值
  847. * @param string $lang_key 变化的值
  848. * @param string $current_status_str 目前状态名称
  849. * @param string $name 字段
  850. * @param string $func 函数
  851. *
  852. * @return string
  853. */
  854. function action_switch(
  855. $id_or_url, $current_value, $value, $lang_key, $current_status_str, $name = 'status', $func = 'setStatus'
  856. ) {
  857. if (is_numeric($id_or_url)) {
  858. $_url = url($func, ['id' => $id_or_url, $name => $value, 'field' => $name]);
  859. } else {
  860. $_url = $id_or_url;
  861. }
  862. $_auth = cmf_auth_check_url(cmf_get_current_admin_id(), $_url);
  863. if (false == $_auth) {
  864. return '';
  865. }
  866. switch ($current_value) {
  867. case 1:
  868. $_class = 'btn-success';
  869. break;
  870. case 2:
  871. $_class = 'btn-default';
  872. break;
  873. case 3:
  874. $_class = 'btn-primary';
  875. break;
  876. default:
  877. $_class = 'btn-info';
  878. break;
  879. }
  880. $_lang_key = $lang_key;
  881. $_target_status_str = lang($_lang_key);
  882. return Index::link(
  883. $_url, '', '', 'btn btn-xs '.$_class.' js-ajax-dialog-btn',
  884. lang('CONFIRM').$_target_status_str.'?', $current_status_str, ''
  885. );
  886. }
  887. /**
  888. * @param int $user_id 用户ID
  889. * @param string $url 访问的URL
  890. *
  891. * @return bool
  892. */
  893. function cmf_auth_check_url($user_id, $url) {
  894. if (1 == $user_id) {
  895. return true;
  896. }
  897. $_name = StrUtils::getRoute($url);
  898. return cmf_auth_check($user_id, $_name);
  899. }