save.blade.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. @extends('admin/layout')
  2. @section('header')
  3. <link href="{{asset('css/plugins/chosen/chosen.css')}}" rel="stylesheet">
  4. <link href="{{asset('js/plugins/bootstrap-select-1.13.9/dist/css/bootstrap-select.min.css')}}" rel="stylesheet">
  5. <link href="{{asset('css/plugins/switchery/switchery.css')}}" rel="stylesheet">
  6. @endsection
  7. <style>
  8. .dropdown-menu {
  9. left: 0 !important;
  10. right: auto !important;
  11. }
  12. </style>
  13. @section('content')
  14. <body class="gray-bg">
  15. <div class="wrapper wrapper-content animated fadeInRight">
  16. <div class="row">
  17. <div class="col-sm-12">
  18. <div class="ibox float-e-margins">
  19. <div class="ibox-content">
  20. <form method="get" class="form-horizontal" id="form">
  21. <div class="form-group">
  22. <label class="col-sm-2 control-label" for="site_id"><span
  23. class="red">* </span>请选择站点:</label>
  24. <div class="col-sm-8 ">
  25. <select data-placeholder="选择站点..." class="my-select" style="width:350px; "
  26. id="site_id" name="site_id">
  27. <option value="">请选择站点</option>
  28. @foreach ($sites as $site)
  29. <option value="{{$site->id}}"
  30. @if(($data->site_id??null)==$site->id) selected @endif
  31. @if(($siteKeep->site_id??null)==$site->id) selected @endif>
  32. {{$site->cn_title}}
  33. </option>
  34. @endforeach
  35. </select>
  36. </div>
  37. </div>
  38. <div class="form-group">
  39. <label class="col-sm-2 control-label" for="translator_id">指派:</label>
  40. <div class="col-sm-8 ">
  41. <select data-placeholder="选择站点..." class="my-select" style="width:350px; "
  42. id="translator_id" name="translator_id">
  43. <option value="">请选择翻译人员</option>
  44. @foreach ($translators as $item)
  45. <option value="{{$item->id}}"
  46. @if(($data->translator_id??null)==$item->id) selected @endif>{{$item->username}}</option>
  47. @endforeach
  48. </select>
  49. </div>
  50. </div>
  51. <div class="form-group">
  52. <label class="col-sm-2 control-label" for="thumb">缩略图:</label>
  53. <div class="col-sm-8">
  54. <button type="button" class="btn btn-primary" id="imageUpload">缩略图上传</button>
  55. </div>
  56. </div>
  57. <div class="form-group" @if (empty($data->thumb))style="display: none"
  58. @endif id="thumb_div">
  59. <div class="col-sm-8 col-sm-offset-2" style="position: relative">
  60. <span style="position: absolute;left: 180px;cursor: pointer" id="delThumb">删除</span>
  61. <img style="height: 150px" src="{{$data->thumb??''}}">
  62. </div>
  63. </div>
  64. <div class="form-group">
  65. <label class="col-sm-2 control-label" for="title"><span class="red">* </span>标题:</label>
  66. <div class="col-sm-8">
  67. <input type="text" class="form-control" id="title" name="title"
  68. value="{{$data->title??''}}">
  69. </div>
  70. </div>
  71. <div class="form-group">
  72. <label class="col-sm-2 control-label" for="content"><span
  73. class="red">* </span>正文:</label>
  74. <div class="col-sm-8">
  75. <!-- 编辑器容器 -->
  76. <script id="content" name="content"
  77. type="text/plain">{!! $data->content??'' !!}</script>
  78. </div>
  79. </div>
  80. <div id="group">
  81. @foreach($data->group??[[]] as $key=>$item)
  82. <div class="form-group">
  83. <label class="col-sm-2 control-label"><span class="red">* </span>中文关键词:</label>
  84. <div class="col-sm-2">
  85. <input type="text" class="form-control" name="cn_keyword" title=""
  86. value="{{$item['cn_keyword']??''}}">
  87. </div>
  88. <label class="col-sm-1 control-label">英文关键词:</label>
  89. <div class="col-sm-2">
  90. <input type="text" class="form-control" name="en_keyword" title=""
  91. value="{{$item['en_keyword']??''}}">
  92. </div>
  93. <label class="col-sm-1 control-label">锚点链接:</label>
  94. <div class="col-sm-2">
  95. <input type="text" class="form-control" name="anchor" title=""
  96. value="{{$item['anchor']??''}}">
  97. </div>
  98. @if($key==0)
  99. <div class="col-sm-1">
  100. <button class="btn btn-primary" type="button"
  101. onclick="units.addGroup()">添加
  102. </button>
  103. </div>
  104. @else
  105. <div class="col-sm-1">
  106. <button class="btn btn-warning" type="button"
  107. onclick="units.delGroup(this)">删除
  108. </button>
  109. </div>
  110. @endif
  111. </div>
  112. @endforeach
  113. </div>
  114. <div class="form-group">
  115. <label class="col-sm-2 control-label" for="translate_title">英文标题:</label>
  116. <div class="col-sm-8">
  117. <input type="text" class="form-control" id="translate_title" name="translate_title"
  118. value="{{$data->translate_title??''}}">
  119. </div>
  120. </div>
  121. <div class="form-group">
  122. <label class="col-sm-2 control-label" for="translate_content">英文正文:</label>
  123. <div class="col-sm-8">
  124. <script id="translate_content" name="translate_content"
  125. type="text/plain">{!! $data->translate_content??'' !!}</script>
  126. </div>
  127. </div>
  128. <div class="hr-line-dashed"></div>
  129. <div class="form-group">
  130. <div class="col-sm-4 col-sm-offset-2">
  131. <button class="btn btn-primary" type="button"
  132. onclick="units.save({{$data->id??0}})">
  133. 保存
  134. </button>
  135. <button class="btn btn-white closeLayer" type="button">取消</button>
  136. </div>
  137. </div>
  138. </form>
  139. </div>
  140. </div>
  141. </div>
  142. </div>
  143. </div>
  144. </body>
  145. @endsection
  146. @section('footer')
  147. @include('vendor.ueditor.assets')
  148. <script src="{{asset('js/plugins/chosen/chosen.jquery.js')}}"></script>
  149. <script src="{{asset('js/plugins/switchery/switchery.js')}}"></script>
  150. <script src="{{asset('js/plugins/bootstrap-select-1.13.9/dist/js/bootstrap-select.min.js')}}"></script>
  151. <script src="{{asset('js/jquery-ui-1.10.4.min.js')}}"></script>
  152. <script>
  153. $(function () {
  154. $('.my-select').selectpicker({
  155. liveSearch: true
  156. });
  157. });
  158. var ue = UE.getEditor('content');
  159. ue.ready(function () {
  160. ue.setHeight(300);
  161. {{--ue.execCommand('serverparam', '_token', '{{ csrf_token() }}'); // 设置 CSRF token.--}}
  162. });
  163. var ueTranslate = UE.getEditor('translate_content');
  164. ueTranslate.ready(function () {
  165. ueTranslate.setHeight(300);
  166. });
  167. var units = {
  168. test: function () {
  169. $("#title").val("");
  170. ue.setContent("");
  171. $("[name=cn_keyword]").val("");
  172. $("[name=en_keyword]").val("");
  173. $("[name=anchor]").val("");
  174. $("#translate_title").val("");
  175. ueTranslate.setContent("");
  176. },
  177. save: function (id) {
  178. var url = '/admin/articles/' + id;
  179. var data = tips.getFormValues('#form');
  180. var group = [], cn_keyword, en_keyword, anchor;
  181. $("#group").find(".form-group").each(function () {
  182. cn_keyword = $(this).find("[name=cn_keyword]").val();
  183. en_keyword = $(this).find("[name=en_keyword]").val();
  184. anchor = $(this).find("[name=anchor]").val();
  185. if (cn_keyword.length !== 0 && en_keyword !== 0 && anchor !== 0) {
  186. group.push({
  187. cn_keyword: cn_keyword,
  188. en_keyword: en_keyword,
  189. anchor: anchor
  190. });
  191. }
  192. });
  193. data.group = group;
  194. data.thumb = $("#thumb_div").find("img").attr('src');
  195. var ajaxConfig = {
  196. url: url,
  197. type: 'put',
  198. data: data,
  199. success: function (result) {
  200. layer.msg(result.message, {icon: 6, time: 1500}, function () {
  201. $("#title").val("");
  202. ue.setContent("");
  203. $("[name=cn_keyword]").val("");
  204. $("[name=en_keyword]").val("");
  205. $("[name=anchor]").val("");
  206. $("#translate_title").val("");
  207. ueTranslate.setContent("");
  208. @php $authUser=auth()->user() @endphp
  209. @if($authUser->role_id==5)
  210. tips.closeParentLayer();
  211. @endif
  212. });
  213. }
  214. };
  215. tips.ajax(ajaxConfig);
  216. },
  217. addGroup: function () {
  218. var html = '<div class="form-group">' +
  219. '<label class="col-sm-2 control-label" >中文关键词:</label>' +
  220. '<div class="col-sm-2">' +
  221. '<input type="text" class="form-control" name="cn_keyword" value="">' +
  222. '</div>' +
  223. '<label class="col-sm-1 control-label">英文关键词:</label>' +
  224. '<div class="col-sm-2">' +
  225. '<input type="text" class="form-control" name="en_keyword" value="">' +
  226. '</div>' +
  227. '<label class="col-sm-1 control-label" >锚点链接:</label>' +
  228. '<div class="col-sm-2">' +
  229. '<input type="text" class="form-control" name="anchor" value="">' +
  230. '</div>' +
  231. '<div class="col-sm-1">' +
  232. '<button class="btn btn-warning" type="button" onclick="units.delGroup(this)">删除</button>' +
  233. '</div>' +
  234. '</div>';
  235. $("#group").append(html);
  236. },
  237. delGroup: function (_this) {
  238. $(_this).parent().parent().remove();
  239. }
  240. };
  241. $(document).on('click', '#imageUpload', function () {
  242. layer.open({
  243. title: "缩略图上传",
  244. type: 2,
  245. content: '/admin/image/index?siteId=' + $("#site_id").val(),
  246. area: ['900px', '530px'],
  247. btn: ['确定', '取消'],
  248. yes: function (index, layero) {
  249. var body = layer.getChildFrame('body', index);
  250. var imgSrc = body.find(".imageActive").find("img").attr('src');
  251. console.log(imgSrc);
  252. if (imgSrc) {
  253. $("#thumb_div").show().find("img").attr('src', imgSrc);
  254. }
  255. layer.close(index)
  256. }
  257. });
  258. });
  259. $(document).on('click', '#delThumb', function () {
  260. $("#thumb_div").hide().find("img").attr('src', '');
  261. });
  262. </script>
  263. @endsection