create.blade.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. {{-- 不继承任何布局 --}}
  2. <!DOCTYPE html>
  3. <html lang="zh-CN">
  4. <head>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <meta name="csrf-token" content="{{ csrf_token() }}">
  8. <title>添加菜单项</title>
  9. {{-- 引入必要的CSS --}}
  10. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  11. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
  12. <style>
  13. body {
  14. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  15. background-color: #f8f9fa;
  16. padding: 20px;
  17. }
  18. .page-header {
  19. display: flex;
  20. justify-content: space-between;
  21. align-items: center;
  22. margin-bottom: 20px;
  23. padding-bottom: 10px;
  24. border-bottom: 1px solid #dee2e6;
  25. }
  26. .page-title h1 {
  27. margin: 0;
  28. font-size: 24px;
  29. color: #333;
  30. }
  31. .page-action {
  32. display: flex;
  33. gap: 10px;
  34. }
  35. .btn {
  36. display: inline-block;
  37. padding: 8px 16px;
  38. border-radius: 4px;
  39. text-decoration: none;
  40. cursor: pointer;
  41. border: 1px solid transparent;
  42. }
  43. .btn-primary {
  44. background-color: #007bff;
  45. color: white;
  46. }
  47. .btn-primary:hover {
  48. background-color: #0056b3;
  49. }
  50. .btn-secondary {
  51. background-color: #6c757d;
  52. color: white;
  53. }
  54. .btn-sm {
  55. padding: 4px 8px;
  56. font-size: 14px;
  57. }
  58. .btn-lg {
  59. padding: 12px 24px;
  60. font-size: 18px;
  61. }
  62. .panel {
  63. background: white;
  64. border: 1px solid #dee2e6;
  65. border-radius: 4px;
  66. margin-bottom: 20px;
  67. }
  68. .panel-header {
  69. padding: 12px 20px;
  70. background-color: #f8f9fa;
  71. border-bottom: 1px solid #dee2e6;
  72. }
  73. .panel-header h3 {
  74. margin: 0;
  75. font-size: 18px;
  76. }
  77. .panel-body {
  78. padding: 20px;
  79. }
  80. .form-group {
  81. margin-bottom: 20px;
  82. }
  83. .form-group label {
  84. display: block;
  85. margin-bottom: 5px;
  86. font-weight: 500;
  87. }
  88. .form-group label.required:after {
  89. content: " *";
  90. color: red;
  91. }
  92. .control {
  93. width: 100%;
  94. padding: 8px 12px;
  95. border: 1px solid #dee2e6;
  96. border-radius: 4px;
  97. font-size: 14px;
  98. }
  99. .control:focus {
  100. border-color: #80bdff;
  101. outline: 0;
  102. box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
  103. }
  104. .control-info {
  105. display: block;
  106. margin-top: 5px;
  107. font-size: 12px;
  108. color: #6c757d;
  109. }
  110. .radio-inline {
  111. margin-right: 20px;
  112. display: inline-flex;
  113. align-items: center;
  114. }
  115. .radio-inline input {
  116. margin-right: 5px;
  117. }
  118. </style>
  119. </head>
  120. <body>
  121. <div class="container-fluid">
  122. <div class="page-header">
  123. <div class="page-title">
  124. <h1><i class="fas fa-plus-circle"></i> 添加菜单项</h1>
  125. </div>
  126. <div class="page-action">
  127. <a href="{{ route('admin.dynamicmenu.index') }}" class="btn btn-secondary">
  128. <i class="fas fa-arrow-left"></i> 返回列表
  129. </a>
  130. </div>
  131. </div>
  132. {{-- 显示错误信息 --}}
  133. @if($errors->any())
  134. <div class="alert alert-danger">
  135. <ul class="mb-0">
  136. @foreach($errors->all() as $error)
  137. <li>{{ $error }}</li>
  138. @endforeach
  139. </ul>
  140. </div>
  141. @endif
  142. <div class="panel">
  143. <div class="panel-header">
  144. <h3>基本信息</h3>
  145. </div>
  146. <div class="panel-body">
  147. <form method="POST" action="{{ route('admin.dynamicmenu.store') }}">
  148. @csrf
  149. {{-- 名称 --}}
  150. <div class="form-group">
  151. <label class="required">名称</label>
  152. <input type="text"
  153. name="name"
  154. class="control"
  155. value="{{ old('name') }}"
  156. required
  157. placeholder="例如:仪表盘">
  158. </div>
  159. {{-- Key --}}
  160. <div class="form-group">
  161. <label class="required">Key</label>
  162. <input type="text"
  163. name="key"
  164. class="control"
  165. value="{{ old('key') }}"
  166. required
  167. placeholder="例如:admin.dashboard">
  168. <small class="control-info">用于权限验证和菜单激活状态判断</small>
  169. </div>
  170. {{-- URL/路由 --}}
  171. <div class="form-group">
  172. <label>URL/路由</label>
  173. <input type="text"
  174. name="route"
  175. class="control"
  176. value="{{ old('route') }}"
  177. placeholder="例如:admin.dashboard">
  178. <small class="control-info">可以是相对路径、完整URL或路由名称</small>
  179. </div>
  180. {{-- 图标 --}}
  181. <div class="form-group">
  182. <label>图标</label>
  183. <input type="text"
  184. name="icon"
  185. class="control"
  186. value="{{ old('icon', 'fas fa-file') }}"
  187. placeholder="例如:fas fa-dashboard、fas fa-users等">
  188. <small class="control-info">FontAwesome图标类名,如:fas fa-home</small>
  189. </div>
  190. {{-- 父级菜单 --}}
  191. <div class="form-group">
  192. <label>父级菜单</label>
  193. <select name="parent_id" class="control">
  194. <option value="">作为顶级菜单</option>
  195. @foreach($menuItems as $menuItem)
  196. <option value="{{ $menuItem->id }}" {{ old('parent_id') == $menuItem->id ? 'selected' : '' }}>
  197. {{ $menuItem->name }}
  198. @if($menuItem->children && $menuItem->children->count() > 0)
  199. (有子菜单)
  200. @endif
  201. </option>
  202. @endforeach
  203. </select>
  204. </div>
  205. {{-- 排序 --}}
  206. <div class="form-group">
  207. <label>排序</label>
  208. <input type="number"
  209. name="order"
  210. class="control"
  211. value="{{ old('order', 0) }}"
  212. min="0">
  213. <small class="control-info">数字越小越靠前</small>
  214. </div>
  215. {{-- 状态 --}}
  216. <div class="form-group">
  217. <label>状态</label>
  218. <div>
  219. <label class="radio-inline">
  220. <input type="radio" name="status" value="1" {{ old('is_active', 1) == 1 ? 'checked' : '' }}>
  221. 启用
  222. </label>
  223. <label class="radio-inline">
  224. <input type="radio" name="status" value="0" {{ old('is_active') == 0 ? 'checked' : '' }}>
  225. 禁用
  226. </label>
  227. </div>
  228. </div>
  229. {{-- 提交按钮 --}}
  230. <div class="form-group">
  231. <button type="submit" class="btn btn-primary btn-lg">
  232. <i class="fas fa-save"></i> 保存菜单项
  233. </button>
  234. <a href="{{ route('admin.dynamicmenu.index') }}" class="btn btn-secondary btn-lg">
  235. <i class="fas fa-times"></i> 取消
  236. </a>
  237. </div>
  238. </form>
  239. </div>
  240. </div>
  241. </div>
  242. {{-- 引入必要的JavaScript --}}
  243. <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  244. <script>
  245. $(document).ready(function() {
  246. // 自动生成key
  247. $('input[name="name"]').on('blur', function() {
  248. var name = $(this).val();
  249. var keyInput = $('input[name="key"]');
  250. if (keyInput.val() === '') {
  251. var key = name.toLowerCase()
  252. .replace(/\s+/g, '.')
  253. .replace(/[^a-z0-9.]/g, '');
  254. keyInput.val('admin.' + key);
  255. }
  256. });
  257. });
  258. </script>
  259. </body>
  260. </html>