Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 

173 рядки
8.0 KiB

  1. <title>编辑自定义页面</title>
  2. <div class="layui-card layadmin-header">
  3. <div class="layui-breadcrumb" lay-filter="breadcrumb">
  4. <a lay-href="">主页</a>
  5. <a><cite>运营设置</cite></a>
  6. <a><cite>自定义页面管理</cite></a>
  7. <a><cite>编辑自定义页面</cite></a>
  8. </div>
  9. </div>
  10. <div class="layui-fluid">
  11. <div class="layui-row layui-col-space15">
  12. <div class="layui-col-md12">
  13. <div class="layui-card">
  14. <div class="layui-card-header">编辑自定义页面</div>
  15. <div class="layui-card-body" pad15>
  16. <form class="layui-form" wid100 lay-filter="LAY-info-form">
  17. <div class="layui-fields">
  18. </div>
  19. <div class="layui-submit">
  20. <div class="layui-form-item">
  21. <div class="layui-input-block">
  22. <input type="hidden" name="id">
  23. <button class="layui-btn" lay-submit lay-filter="submit">确认</button>
  24. </div>
  25. </div>
  26. </div>
  27. </form>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. <script>
  34. var $ = layui.$;
  35. function initRuleView(obj) {
  36. value = obj.value ? JSON.parse(obj.value) : [];
  37. var tbody = layui.$(obj).parents('.layui-form-item').find('tbody');
  38. layui.each(value, function (k, v) {
  39. html = '<tr>' +
  40. '<td><select class="param_type">' +
  41. '<option value="string"' + (v.type === 'string' ? ' selected' : '') + '>文本</option>' +
  42. '<option value="array"' + (v.type === 'array' ? ' selected' : '') + '>数组</option>' +
  43. '</select></td>' +
  44. '<td><input type="text" class="layui-input param_key" value="' + v.key + '"></td>' +
  45. '<td><input type="text" class="layui-input param_value" value="' + v.value + '"></td>' +
  46. '<td><button class="layui-btn layui-btn-danger" onclick="layui.$(this).parents(\'tr\').remove()">删除</button></td>' +
  47. '</tr>';
  48. tbody.append(html);
  49. });
  50. layui.form.render();
  51. }
  52. </script>
  53. <script type="text/html" id="params">
  54. <div class="layui-form-item">
  55. <input type="hidden" name="{{d.key}}" value="" onchange="initRuleView(this)">
  56. <label class="layui-form-label">{{d.name}}</label>
  57. <div class="layui-form-mid layui-word-aux">
  58. 在模板内使用 <span style="color: #FF5722;">$params['参数名']</span> 或 <span
  59. style="color: #FF5722;">$params.参数名</span> 调用,数组请输入json字符串
  60. </div>
  61. <div class="layui-input-block">
  62. <div class="layui-row replace-rule-box">
  63. <table class="layui-table">
  64. <colgroup>
  65. <col width="15%">
  66. <col width="20%">
  67. <col width="55%">
  68. <col width="10%">
  69. </colgroup>
  70. <thead>
  71. <tr>
  72. <th>类型</th>
  73. <th>参数名</th>
  74. <th>参数值</th>
  75. <th class="text-align: center;">
  76. <button class="layui-btn btn-add-param" type="button">添加</button>
  77. </th>
  78. </tr>
  79. </thead>
  80. <tbody></tbody>
  81. </table>
  82. </div>
  83. </div>
  84. </div>
  85. </script>
  86. <script>
  87. var config;
  88. layui.admin.req({
  89. url: '/manage/data/response.json',
  90. method: 'POST',
  91. data: {custompagetemplate: 'kvselect'},
  92. success: function (res) {
  93. config = {
  94. api: {
  95. submit: '/manage/system/custompage/edit.json'
  96. },
  97. done: function () {
  98. layui.$('.btn-add-param').click(function () {
  99. var tbody = layui.$(this).parents('.layui-form-item').find('tbody');
  100. html = '<tr>' +
  101. '<td><select class="param_type">' +
  102. '<option value="string">文本</option>' +
  103. '<option value="array">数组</option>' +
  104. '</select></td>' +
  105. '<td><input type="text" class="layui-input param_key" placeholder="请输入参数名"></td>' +
  106. '<td><input type="text" class="layui-input param_value" placeholder="请输入参数值"></td>' +
  107. '<td><button class="layui-btn layui-btn-danger" onclick="layui.$(this).parents(\'tr\').remove()">删除</button></td>' +
  108. '</tr>';
  109. tbody.append(html);
  110. layui.form.render();
  111. });
  112. },
  113. submit: function (obj) {
  114. var types = layui.$('.param_type'),
  115. keys = layui.$('.param_key'),
  116. values = layui.$('.param_value'),
  117. params = [];
  118. if (types.length !== keys.length || keys.length !== values.length) {
  119. layui.layer.msg('参数错误,请刷新页面后重试');
  120. return false;
  121. }
  122. types.each(function (k, v) {
  123. params.push({
  124. key: keys[k].value,
  125. value: values[k].value,
  126. type: types[k].value,
  127. });
  128. });
  129. obj.field.params = JSON.stringify(params);
  130. layui.admin.req({
  131. url: config.api.submit,
  132. data: obj.field,
  133. method: 'POST',
  134. success: function (res) {
  135. if (typeof config.submitSuccess === 'function') {
  136. config.submitSuccess(res);
  137. } else {
  138. layui.admin.success('添加成功', {
  139. yes: function (index) {
  140. layui.index.render();
  141. },
  142. btn2: function () {
  143. location.hash = config.url.index;
  144. }
  145. })
  146. }
  147. }
  148. });
  149. return false;
  150. },
  151. fields: [
  152. {name: 'URL', key: 'url', type: 'text',intro:'请不要和其他页面url冲突,可以设置成比如“/gg.html”男生频道 “/active/yuandan.html”元旦活动'},
  153. {name: '标题', key: 'title', type: 'text', intro: '在模板内使用 $title 调用'},
  154. {name: '描述', key: 'desc', type: 'textarea', intro: '在模板内使用 $description 调用'},
  155. {name: '关键词', key: 'keywords', type: 'textarea', intro: '在模板内使用 $keywords 调用'},
  156. {
  157. name: '模板',
  158. key: 'template',
  159. type: 'select',
  160. extra: res.data.custompagetemplate.kvselect,
  161. intro: '模板文件请放到 <span style="color: #FF5722;">/template/*/custom/</span> 目录下,请pc和手机模板都制作好!'
  162. },
  163. {name: '自定义参数', key: 'params', templet: '#params'},
  164. {name: '状态', key: 'status', type: 'switch', extra: '显示|隐藏'},
  165. ],
  166. };
  167. layui.use('curd/addOrEdit', layui.factory('curd/addOrEdit'));
  168. }
  169. });
  170. </script>