index.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <?php
  2. use yii\grid\GridView;
  3. use common\helpers\Url;
  4. use common\helpers\Html;
  5. use common\helpers\AddonHelper;
  6. use common\enums\OfficialEnum;
  7. use common\helpers\StringHelper;
  8. $this->title = '已安装的插件';
  9. $this->params['breadcrumbs'][] = ['label' => $this->title];
  10. ?>
  11. <div class="row">
  12. <div class="col-sm-12">
  13. <div class="nav-tabs-custom">
  14. <ul class="nav nav-tabs">
  15. <li class="active"><a href="<?= Url::to(['index']) ?>">已安装的插件</a></li>
  16. <li><a href="<?= Url::to(['local']) ?>">安装插件</a></li>
  17. <li><a href="<?= Url::to(['create']) ?>">设计新插件</a></li>
  18. </ul>
  19. <div class="tab-content">
  20. <div class="active tab-pane">
  21. <?= GridView::widget([
  22. 'dataProvider' => $dataProvider,
  23. 'filterModel' => $searchModel,
  24. // 重新定义分页样式
  25. 'tableOptions' => [
  26. 'class' => 'table table-hover rf-table',
  27. 'fixedNumber' => 2,
  28. 'fixedRightNumber' => 1,
  29. ],
  30. 'columns' => [
  31. [
  32. 'class' => 'yii\grid\SerialColumn',
  33. ],
  34. [
  35. 'attribute' => 'icon',
  36. 'label' => '图标',
  37. 'filter' => false, //不显示搜索框
  38. 'headerOptions' => ['class' => 'col-md-1'],
  39. 'value' => function ($model) {
  40. if ($path = AddonHelper::getAddonIcon($model['name'])) {
  41. return Html::img($path, [
  42. 'class' => 'img-rounded m-t-xs img-responsive',
  43. 'width' => '64',
  44. 'height' => '64',
  45. ]);
  46. }
  47. return '<span class="iconfont iconchajian blue" style="font-size: 50px"></span>';
  48. },
  49. 'format' => 'raw'
  50. ],
  51. [
  52. 'attribute' => 'title',
  53. // 'filter' => false, //不显示搜索框
  54. 'value' => function ($model) {
  55. $str = '<h4> ' . $model['title'] . '</h4>';
  56. $str .= "<small>" . $model['name'] . "</small>";
  57. return $str;
  58. },
  59. 'format' => 'raw'
  60. ],
  61. [
  62. 'attribute' => 'author',
  63. 'filter' => false, //不显示搜索框
  64. ],
  65. [
  66. 'label' => '组别',
  67. 'attribute' => 'group',
  68. 'filter' => false, //不显示搜索框
  69. 'value' => function ($model) use ($addonsGroup) {
  70. return '<span class="label label-outline-primary">' . $addonsGroup[$model->group]['title'] . '</span> ';
  71. },
  72. 'format' => 'raw'
  73. ],
  74. [
  75. 'label' => '功能支持',
  76. 'filter' => false, //不显示搜索框
  77. 'value' => function ($model) {
  78. $str = '';
  79. $model['is_merchant_route_map'] == true && $str .= '<span class="label label-outline-info">商户路由映射</span>';
  80. return $str;
  81. },
  82. 'format' => 'raw'
  83. ],
  84. [
  85. 'attribute' => 'brief_introduction',
  86. 'filter' => false, //不显示搜索框
  87. ],
  88. [
  89. 'attribute' => 'version',
  90. 'format' => 'raw',
  91. 'filter' => false, //不显示搜索框
  92. 'value' => function ($model) use ($newestVersion) {
  93. $str = $model->version;
  94. if (
  95. isset($newestVersion[$model->name]) &&
  96. StringHelper::strToInt($newestVersion[$model->name]) > StringHelper::strToInt($model->version)
  97. ) {
  98. $str .= ' <span class="label label-outline-warning">' . $newestVersion[$model->name] . '</span>';
  99. }
  100. return $str;
  101. },
  102. ],
  103. [
  104. 'header' => "操作",
  105. 'class' => 'yii\grid\ActionColumn',
  106. 'template' => '{onLineUpgrade} {upgrade} {upgradeSql} {edit} {status} {delete}',
  107. 'buttons' => [
  108. 'onLineUpgrade' => function ($url, $model, $key) {
  109. return Html::linkButton(['on-line-upgrade', 'name' => $model->name], '在线升级', [
  110. 'data-name' => $model->name,
  111. 'onclick' => "onLineUpgrade(this);return false;"
  112. ]);
  113. },
  114. 'upgrade' => function ($url, $model, $key) {
  115. return Html::linkButton(['install', 'name' => $model->name, 'installData' => false], '更新配置', [
  116. 'onclick' => "upgrade(this);return false;"
  117. ]);
  118. },
  119. 'upgradeSql' => function ($url, $model, $key) {
  120. return Html::linkButton(['upgrade', 'name' => $model->name], '数据库升级', [
  121. 'onclick' => "upgradeSqlAffirm(this);return false;",
  122. ]);
  123. },
  124. 'edit' => function ($url, $model, $key) {
  125. return Html::edit(['ajax-edit', 'id' => $model->id], '编辑', [
  126. 'data-toggle' => 'modal',
  127. 'data-target' => '#ajaxModal',
  128. ]);
  129. },
  130. 'status' => function ($url, $model, $key) {
  131. if ($model->name == OfficialEnum::AUTHORITY) {
  132. return false;
  133. }
  134. return Html::status($model->status);
  135. },
  136. 'delete' => function ($url, $model, $key) {
  137. if ($model->name == OfficialEnum::AUTHORITY) {
  138. return false;
  139. }
  140. return Html::linkButton(['un-install', 'name' => $model->name], '卸载', [
  141. 'class' => 'btn btn-danger btn-sm',
  142. 'onclick' => "rfTwiceAffirm(this, '确认卸载插件么?', '请谨慎操作');return false;",
  143. ]);
  144. },
  145. ],
  146. ],
  147. ],
  148. ]); ?>
  149. </div>
  150. </div>
  151. </div>
  152. </div>
  153. </div>
  154. <script>
  155. function upgradeSqlAffirm(that) {
  156. var title = '确认升级数据库吗?';
  157. var dialogText = '会执行更新数据库字段升级等功能';
  158. var href = $(that).attr('href');
  159. swal(title, {
  160. buttons: {
  161. cancel: "取消",
  162. defeat: '确定'
  163. },
  164. title: title,
  165. text: dialogText,
  166. // icon: "warning",
  167. }).then(function (value) {
  168. switch (value) {
  169. case "defeat":
  170. upgradeSql(href);
  171. break;
  172. default:
  173. }
  174. });
  175. return false;
  176. }
  177. function upgradeSql(href) {
  178. swal({
  179. title: '升级中...',
  180. text: '请不要关闭窗口,等待升级',
  181. button: "确定",
  182. });
  183. $.ajax({
  184. type: "get",
  185. url: href,
  186. dataType: "json",
  187. success: function (data) {
  188. if (parseInt(data.code) === 200) {
  189. swal("数据库升级成功", "小手一抖就打开了一个框", "success").then((value) => {
  190. location.reload();
  191. });
  192. } else {
  193. rfMsg(data.message);
  194. }
  195. }
  196. });
  197. }
  198. function upgrade(that) {
  199. var href = $(that).attr('href');
  200. swal({
  201. title: '更新配置中...',
  202. text: '请不要关闭窗口,等待更新配置',
  203. button: "确定",
  204. });
  205. $.ajax({
  206. type: "get",
  207. url: href,
  208. dataType: "json",
  209. success: function (data) {
  210. if (parseInt(data.code) === 200) {
  211. swal("更新配置成功", "小手一抖就打开了一个框", "success").then((value) => {
  212. location.reload();
  213. });
  214. } else {
  215. rfMsg(data.message);
  216. }
  217. }
  218. });
  219. }
  220. function onLineUpgrade(that) {
  221. var href = $(that).attr('href');
  222. var name = $(that).data('name');
  223. var title = '确认在线升级吗?';
  224. var dialogText = '请注意先备份好服务器文件信息及数据库信息';
  225. swal(title, {
  226. buttons: {
  227. cancel: "取消",
  228. defeat: '确定'
  229. },
  230. title: title,
  231. text: dialogText,
  232. // icon: "warning",
  233. }).then(function (value) {
  234. switch (value) {
  235. case "defeat":
  236. onLineUpgradeExecute(href, name);
  237. break;
  238. default:
  239. }
  240. });
  241. }
  242. function onLineUpgradeExecute(href, name) {
  243. swal({
  244. title: '在线升级中...',
  245. text: '请不要关闭窗口',
  246. button: "确定",
  247. });
  248. $.ajax({
  249. type: "get",
  250. url: href,
  251. dataType: "json",
  252. success: function (data) {
  253. if (parseInt(data.code) === 200) {
  254. swal(
  255. "更新配置中...",
  256. "请不要关闭窗口,等待更新配置",
  257. ).then((value) => {
  258. });
  259. var updateUrl = "<?= Url::to(['install', 'installData' => false])?>";
  260. updateUrl += '&name=' + name;
  261. $.ajax({
  262. type: "get",
  263. url: updateUrl,
  264. dataType: "json",
  265. success: function (data) {
  266. if (parseInt(data.code) === 200) {
  267. swal("升级成功", "小手一抖就打开了一个框", "success").then((value) => {
  268. location.reload();
  269. });
  270. } else {
  271. swal({
  272. title: '升级提示',
  273. text: data.message,
  274. button: "确定",
  275. });
  276. }
  277. }
  278. });
  279. } else {
  280. setTimeout(function () {
  281. swal({
  282. title: '升级提示',
  283. text: data.message,
  284. button: "确定",
  285. });
  286. }, 1000)
  287. }
  288. }
  289. });
  290. }
  291. </script>
粤ICP备19079148号