question.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. const option_name = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'];
  2. var init_count = 0;
  3. var fa_form;
  4. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'upload'], function ($, undefined, Backend, Table, Form, Upload) {
  5. var Controller = {
  6. index: function () {
  7. // 初始化表格参数配置
  8. Table.api.init({
  9. extend: {
  10. index_url: 'exam/question/index' + location.search,
  11. add_url: 'exam/question/add',
  12. edit_url: 'exam/question/edit',
  13. del_url: 'exam/question/del',
  14. multi_url: 'exam/question/multi',
  15. import_url: 'exam/question/import',
  16. table: 'exam_question',
  17. }
  18. });
  19. var table = $("#table");
  20. //在普通搜索渲染后
  21. table.on('post-common-search.bs.table', function (event, table) {
  22. let form = $("form", table.$commonsearch);
  23. $("input[name='cate_id']", form).addClass("selectpage").data("source", "exam/cate/selectpage").data("params", {"custom[kind]": "QUESTION","isTree":true}).data("orderBy", "sort desc");
  24. // $("input[name='is_material_child']", form).val(0);
  25. // $("input[name='exam_type_id']", form).addClass("selectpage").data("source", "exam_type/index").data("orderBy", "sort desc");
  26. Form.events.cxselect(form);
  27. Form.events.selectpage(form);
  28. });
  29. //当内容渲染完成给编辑按钮添加`data-area`属性,点击列表编辑按钮时全屏
  30. table.on('post-body.bs.table', function (e, settings, json, xhr) {
  31. $(".btn-add").data("area", ["100%", "100%"]);
  32. $(".btn-editone").data("area", ["100%", "100%"]);
  33. });
  34. // 初始化表格
  35. table.bootstrapTable({
  36. url: $.fn.bootstrapTable.defaults.extend.index_url,
  37. pk: 'id',
  38. sortName: 'id',
  39. search: false,
  40. showExport: false,//隐藏导出
  41. showToggle: false,//隐藏浏览模式
  42. showColumns: false,//隐藏显示隐藏模式
  43. searchFormVisible: true,//默认显示搜索表单
  44. escape:false,//false解析html,默认为true不解析
  45. columns: [
  46. [
  47. {checkbox: true},
  48. {field: 'id', title: __('Id')},
  49. {field: 'cate_id', title: __('Cate_id'), autocomplete: false, visible: false},
  50. {field: 'cate.name', title: __('Cate_id'), operate: false},
  51. // {field: 'exam_type_id', title: __('Exam_type_id'), visible: false},
  52. // {field: 'examtype.name', title: __('Exam_type_id'), operate: false},
  53. {
  54. field: 'kind',
  55. title: __('Kind'),
  56. searchList: {"JUDGE": __('Judge'), "SINGLE": __('Single'), "MULTI": __('Multi'), /*"FILL": __('Fill'),*/ "SHORT": __('Short')/*, "MATERIAL": __('Material')*/},
  57. formatter: Table.api.formatter.normal,
  58. // operate: "IN",
  59. },
  60. {field: 'title', title: __('Title'), autocomplete: false, operate: 'LIKE', formatter: Table.api.formatter.content},
  61. /*{
  62. field: 'is_material_child',
  63. title: __('属于材料题子题'),
  64. searchList: {"0": __('否'), "1": __('是')},
  65. defaultValue: 0,
  66. visible: false
  67. },*/
  68. /* {
  69. field: 'difficulty',
  70. title: __('Difficulty'),
  71. searchList: {"EASY": __('Easy'), "GENERAL": __('General'), "HARD": __('Hard')},
  72. formatter: Table.api.formatter.normal
  73. },*/
  74. {
  75. field: 'answer', title: __('Answer'), halign: 'center', align: 'left', operate: false, formatter: function (value, row, index) {
  76. var answer = value;
  77. if (row.kind == 'FILL') {
  78. try {
  79. answer = '';
  80. let fill_answers = JSON.parse(row.answer);
  81. for (let i = 0; i < fill_answers.length; i++) {
  82. answer += '填空位' + (i + 1) + ':' + fill_answers[i].answers.join('、') + '<br>';
  83. }
  84. } catch (e) {
  85. console.log('answer', index, answer, e);
  86. return value;
  87. }
  88. } else if (row.kind == 'SHORT') {
  89. try {
  90. let short_answers = JSON.parse(row.answer);
  91. answer = '标准答案:' + short_answers.answer + '<br>';
  92. for (let i = 0; i < short_answers.config.length; i++) {
  93. // answer += '关键词' + (i + 1) + ':' + short_answers[i].answer + '<br>';
  94. answer += '关键词' + (i + 1) + ':' + short_answers.config[i].answer + '(' + short_answers.config[i].score + '分)<br>';
  95. }
  96. } catch (e) {
  97. console.log('short answer', index, answer, e);
  98. return value;
  99. }
  100. } else if (row.kind == 'MATERIAL') {
  101. return '-';
  102. }
  103. console.log('answer', value, answer);
  104. return answer;
  105. }
  106. },
  107. {
  108. field: 'status',
  109. title: __('Status'),
  110. searchList: {"NORMAL": __('Normal'), "HIDDEN": __('Hidden')},
  111. formatter: Table.api.formatter.status,
  112. operate: false
  113. },
  114. /*{
  115. field: 'createtime',
  116. title: __('Createtime'),
  117. operate: 'RANGE',
  118. addclass: 'datetimerange',
  119. autocomplete: false,
  120. formatter: Table.api.formatter.datetime
  121. },*/
  122. /*{
  123. field: 'updatetime',
  124. title: __('Updatetime'),
  125. operate: 'RANGE',
  126. addclass: 'datetimerange',
  127. autocomplete: false,
  128. formatter: Table.api.formatter.datetime
  129. },*/
  130. {
  131. field: 'operate',
  132. title: __('Operate'),
  133. table: table,
  134. events: Table.api.events.operate,
  135. formatter: Table.api.formatter.operate
  136. }
  137. ]
  138. ]
  139. });
  140. // 为表格绑定事件
  141. Table.api.bindevent(table);
  142. // 打开导入页面
  143. $('.btn-importPage').click(function () {
  144. Fast.api.open('exam/question/import', '导入试题', {
  145. area: ['800px', '380px'],
  146. callback: function (data) {
  147. table.bootstrapTable('refresh');
  148. }
  149. });
  150. });
  151. },
  152. recyclebin: function () {
  153. // 初始化表格参数配置
  154. Table.api.init({
  155. extend: {
  156. 'dragsort_url': ''
  157. }
  158. });
  159. var table = $("#table");
  160. // 初始化表格
  161. table.bootstrapTable({
  162. url: 'exam/question/recyclebin' + location.search,
  163. pk: 'id',
  164. sortName: 'id',
  165. escape:false,//false解析html,默认为true不解析
  166. columns: [
  167. [
  168. {checkbox: true},
  169. {field: 'id', title: __('Id')},
  170. {field: 'title', title: __('Title'), align: 'left', formatter: Table.api.formatter.content},
  171. {
  172. field: 'deletetime',
  173. title: __('Deletetime'),
  174. operate: 'RANGE',
  175. addclass: 'datetimerange',
  176. formatter: Table.api.formatter.datetime
  177. },
  178. {
  179. field: 'operate',
  180. width: '130px',
  181. title: __('Operate'),
  182. table: table,
  183. events: Table.api.events.operate,
  184. buttons: [
  185. {
  186. name: 'Restore',
  187. text: __('Restore'),
  188. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  189. icon: 'fa fa-rotate-left',
  190. url: 'exam/question/restore',
  191. refresh: true
  192. },
  193. {
  194. name: 'Destroy',
  195. text: __('Destroy'),
  196. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  197. icon: 'fa fa-times',
  198. url: 'exam/question/destroy',
  199. refresh: true
  200. }
  201. ],
  202. formatter: Table.api.formatter.operate
  203. }
  204. ]
  205. ]
  206. });
  207. // 为表格绑定事件
  208. Table.api.bindevent(table);
  209. },
  210. add: function () {
  211. fa_form = Form
  212. Controller.api.bindevent();
  213. $('input[name="row[kind]"]')[0].click()
  214. setTimeout(() => {
  215. optionCtrl(Form);
  216. init_count++;
  217. }, 500)
  218. },
  219. edit: function () {
  220. Controller.api.bindevent();
  221. optionCtrl(Form, 'edit');
  222. init_count++;
  223. },
  224. image: function () {
  225. // Controller.api.bindevent();
  226. Form.api.bindevent($("form[role=form]"), function (data, ret) {
  227. let img = $('#c-imgs').val();
  228. if (!img) {
  229. Toastr.warning('未上传图片文件');
  230. }
  231. Fast.api.close(img);
  232. }, function (data, ret) {
  233. Toastr.error("失败");
  234. });
  235. },
  236. import: function () {
  237. Controller.api.bindevent();
  238. // 手动绑定导入事件
  239. Upload.api.upload($('.btn-import'), function (data, ret) {
  240. let cate = $('#c-cate_id').val();
  241. // let exam_type = $('#c-exam_type_id').val();
  242. if (!cate) { // || !exam_type
  243. Fast.api.msg('请先选择所属类型及考试分类再进行上传!')
  244. return false;
  245. }
  246. $('#file_url').val(data.url);
  247. Fast.api.ajax({
  248. url: 'exam/question/importExcel',
  249. data: {
  250. file: data.url,
  251. cate: cate,
  252. // exam_type: exam_type
  253. },
  254. }, function (data, ret) {
  255. console.log(data, ret)
  256. $('#question_count').html(`本次上传识别到 ${data.count} 道题`)
  257. });
  258. });
  259. $('#test').click(function () {
  260. Fast.api.ajax({
  261. url: 'exam/question/test',
  262. }, function (data, ret) {
  263. console.log(data, ret)
  264. return false
  265. })
  266. })
  267. },
  268. // 选择题目页面
  269. select: function () {
  270. // 初始化表格参数配置
  271. Table.api.init({
  272. extend: {
  273. index_url: 'exam/question/select' + location.search,
  274. // add_url: 'exam/question/add',
  275. // edit_url: 'exam/question/edit',
  276. // del_url: 'exam/question/del',
  277. // multi_url: 'exam/question/multi',
  278. // import_url: 'exam/question/import',
  279. table: 'exam_question',
  280. }
  281. });
  282. var table = $("#table");
  283. //在普通搜索渲染后
  284. table.on('post-common-search.bs.table', function (event, table) {
  285. let form = $("form", table.$commonsearch);
  286. $("input[name='cate_id']", form).addClass("selectpage").data("source", "exam/cate/selectpage").data("params", {"custom[kind]": "QUESTION"}).data("orderBy", "sort desc");
  287. // $("input[name='exam_type_id']", form).addClass("selectpage").data("source", "exam_type/index").data("orderBy", "sort desc");
  288. Form.events.cxselect(form);
  289. Form.events.selectpage(form);
  290. });
  291. // 初始化表格
  292. table.bootstrapTable({
  293. url: $.fn.bootstrapTable.defaults.extend.index_url,
  294. pk: 'id',
  295. sortName: 'id',
  296. search: false,
  297. showExport: false,//隐藏导出
  298. showToggle: false,//隐藏浏览模式
  299. showColumns: false,//隐藏显示隐藏模式
  300. searchFormVisible: true,//默认显示搜索表单
  301. escape:false,//false解析html,默认为true不解析
  302. columns: [
  303. [
  304. {checkbox: true},
  305. {field: 'id', title: __('Id')},
  306. {field: 'cate_id', title: __('Cate_id'), autocomplete: false, visible: false},
  307. {field: 'cate.name', title: __('Cate_id'), operate: false},
  308. {
  309. field: 'kind',
  310. title: __('Kind'),
  311. searchList: {"JUDGE": __('Judge'), "SINGLE": __('Single'), "MULTI": __('Multi'), "FILL": __('Fill'), "SHORT": __('Short'), "MATERIAL": __('Material')},
  312. formatter: Table.api.formatter.normal
  313. },
  314. {field: 'title', title: __('Title'), autocomplete: false, operate: 'LIKE', formatter: Table.api.formatter.content},
  315. {
  316. field: 'difficulty',
  317. title: __('Difficulty'),
  318. searchList: {"EASY": __('Easy'), "GENERAL": __('General'), "HARD": __('Hard')},
  319. formatter: Table.api.formatter.normal
  320. },
  321. {
  322. field: 'answer', title: __('Answer'), halign: 'center', align: 'left', operate: false, formatter: function (value, row, index) {
  323. var answer = value;
  324. // 填空题
  325. if (row.kind == 'FILL') {
  326. try {
  327. answer = '';
  328. let fill_answers = JSON.parse(row.answer);
  329. for (let i = 0; i < fill_answers.length; i++) {
  330. answer += '填空位' + (i + 1) + ':' + fill_answers[i].answers.join('、') + '<br>';
  331. }
  332. } catch (e) {
  333. console.log('fill answer', index, answer, e);
  334. return value;
  335. }
  336. } else if (row.kind == 'SHORT') {
  337. try {
  338. answer = '';
  339. let short_answers = JSON.parse(row.answer);
  340. for (let i = 0; i < short_answers.length; i++) {
  341. // answer += '关键词' + (i + 1) + ':' + short_answers[i].answer + '<br>';
  342. answer += '关键词' + (i + 1) + ':' + short_answers[i].answer + '(' + short_answers[i].score + '分)<br>';
  343. }
  344. } catch (e) {
  345. console.log('short answer', index, answer, e);
  346. return value;
  347. }
  348. }
  349. return answer;
  350. }
  351. },
  352. {
  353. field: 'status',
  354. title: __('Status'),
  355. searchList: {"NORMAL": __('Normal'), "HIDDEN": __('Hidden')},
  356. formatter: Table.api.formatter.status,
  357. operate: false
  358. },
  359. ]
  360. ]
  361. });
  362. // 为表格绑定事件
  363. Table.api.bindevent(table);
  364. // 批量确认选择
  365. $('.btn-confirm-choose').click(function () {
  366. // Table.api.select
  367. // var ids = Table.api.selectedids(table);//获取选中列的id
  368. // if (ids.length == 0){
  369. // layer.alert("请选择题目");
  370. // return false;
  371. // }
  372. var rows = $("#table").bootstrapTable('getSelections');
  373. console.log('select questions', rows, rows.length, 'length')
  374. if (rows.length == 0){
  375. layer.alert("请选择题目");
  376. return false;
  377. }
  378. Fast.api.close(rows);
  379. });
  380. },
  381. api: {
  382. bindevent: function () {
  383. Form.api.bindevent(
  384. $("form[role=form]"),
  385. () => {
  386. console.log('success', this)
  387. },
  388. () => {
  389. console.log('fail', this)
  390. },
  391. () => {
  392. console.log('submit', this, valid_result)
  393. // 触发验证
  394. $('#valid').click()
  395. return valid_result;
  396. },
  397. );
  398. // 题库和材料题联动
  399. $('#c-cate_id').on('change', function () {
  400. $("#c-material_question_id").selectPageClear()
  401. });
  402. $("#c-material_question_id").data("params", function () {
  403. const cate_id = $("input[name='row[cate_id]']").val();
  404. return {
  405. custom: {
  406. cate_id: cate_id,
  407. kind: 'MATERIAL',
  408. }
  409. }
  410. });
  411. }
  412. }
  413. };
  414. return Controller;
  415. });
  416. function optionCtrl(Form, type = 'add') {
  417. console.log('init_count', init_count)
  418. if (init_count > 0) {
  419. return;
  420. }
  421. $('.btn-append').html('<i class="fa fa-plus"></i> 添加选项');
  422. // 添加选项
  423. $(document).on("fa.event.appendfieldlist", '[data-name="row[options_json]"] .btn-append', function () {
  424. console.log('append xxx')
  425. $('.btn-dragsort').hide();
  426. let dd = $('dd[class="form-inline"]');
  427. let options_img = $('#c-options_img');
  428. let question_num = dd.length;
  429. if (question_num > 8) {
  430. Toastr.error('选项不能超过8个');
  431. // $('input[name="row[options_json]['+question_num+'][value]"]').next().click();
  432. // $('input[name="row[options_json]['+question_num+'][value]"]').parent().remove();
  433. dd[question_num - 1].remove();
  434. return false;
  435. }
  436. // 重排选项名称
  437. sortOptions();
  438. // 删除选项
  439. bindRemoveOption();
  440. // 添加上传图片控件
  441. // $(dd[question_num - 1]).append(imageUploadHtml('row[options_json][' + (question_num - 1) + '][image]'));
  442. // $(dd[question_num - 1]).append(editorHtml('row[options_json][' + (question_num - 1) + '][image]'));
  443. // Form.api.bindevent($("form[role=form]"));
  444. // 添加设为答案按钮
  445. $(dd[question_num - 1]).append('<span class="btn btn-sm btn-info btn-set m-l-5" data-type="SET">设为答案</span>');
  446. // 添加上传图片按钮
  447. $(dd[question_num - 1]).append('<span class="btn btn-sm btn-success btn-image m-l-5" data-type="UPLOAD" id="upload_' + (question_num - 1) + '" data-id="' + (question_num - 1) + '">上传图片</span>');
  448. if (options_img.val()) {
  449. let option_img_json = JSON.parse(options_img.val())
  450. if(option_img_json) {
  451. option_img_json.forEach((item) => {
  452. let index = option_name.indexOf(item.key)
  453. // 不知为啥会执行两次
  454. if ($('.option-preview-' + index).length === 0) {
  455. $(dd[index]).append(previewHtml(index, item.value));
  456. }
  457. })
  458. }
  459. }
  460. bindSetAnswer();
  461. bindUploadImage();
  462. if (type === 'edit') {
  463. initEditBtn()
  464. }
  465. });
  466. }
  467. // 编辑时处理按钮文本
  468. function initEditBtn() {
  469. let answer = $('#c-answer').val()
  470. if (!answer) return
  471. console.log('initEditBtn answer', answer)
  472. $('.btn-set').each(function (index, ele) {
  473. const key = $($(ele).parent().find('input')[0]).val()
  474. console.log('initEditBtn key', key)
  475. if (key && answer.indexOf(key) > -1) {
  476. $(ele).removeClass('btn-info').addClass('btn-warning').text('取消答案').data('type', 'CANCEL')
  477. }
  478. })
  479. }
  480. // 监听删除选项按钮事件
  481. function bindRemoveOption() {
  482. $('.btn-remove').click(function () {
  483. //延迟重排选项名称
  484. setTimeout(() => {
  485. sortOptions();
  486. }, 300);
  487. });
  488. }
  489. // 监听设为答案按钮事件
  490. function bindSetAnswer() {
  491. $('.btn-set').unbind('click').click(function () {
  492. let type = $(this).data('type');
  493. let name = $($(this).parent().children('input')[0]).val();
  494. let answer_type = getAnswerType();
  495. let c_answer = $('#c-answer');
  496. // 设为答案
  497. if (type === 'SET') {
  498. // 单选
  499. if (answer_type === 'SINGLE' || !c_answer.val()) {
  500. c_answer.val(name);
  501. $('.btn-set').removeClass('btn-warning').addClass('btn-info').text('设为答案').data('type', 'SET');
  502. $(this).removeClass('btn-info').addClass('btn-warning').text('取消答案').data('type', 'CANCEL');
  503. } else {// 多选
  504. let answers = c_answer.val();
  505. let answer_arr = answers.split(',');
  506. answer_arr.push(name);
  507. answer_arr = unique(answer_arr);
  508. c_answer.val(answer_arr.join(','));
  509. $(this).removeClass('btn-info').addClass('btn-warning').text('取消答案').data('type', 'CANCEL');
  510. }
  511. } else {// 取消答案
  512. // 单选
  513. if (answer_type === 'SINGLE') {
  514. if (c_answer.val() === name) {
  515. c_answer.val('');
  516. $(this).removeClass('btn-warning').addClass('btn-info').text('设为答案').data('type', 'SET');
  517. }
  518. } else {// 多选
  519. let answers = c_answer.val();
  520. let answer_arr = answers.split(',');
  521. answer_arr = answer_arr.filter(function (item) {
  522. return item !== name;
  523. });
  524. console.log(answer_arr);
  525. c_answer.val(answer_arr.join(','));
  526. $(this).removeClass('btn-warning').addClass('btn-info').text('设为答案').data('type', 'SET');
  527. }
  528. }
  529. });
  530. }
  531. // 监听上传图片按钮事件
  532. function bindUploadImage() {
  533. $('.btn-image').unbind('click').click(function () {
  534. let index = $(this).data('id')
  535. Fast.api.open('exam/question/image', '选项图片', {
  536. area: ['500px', '300px'],
  537. callback: function (data) {
  538. if (!data) {
  539. return
  540. }
  541. // if ($($('dd[class="form-inline"]')[index]).find('.plupload-preview').length > 0) {
  542. // return
  543. // }
  544. // 加预览图
  545. $($('dd[class="form-inline"]')[index]).append(previewHtml(index, data))
  546. // 赋值图片数据
  547. $('#c-options_img').html(JSON.stringify(getAllPreview()))
  548. bindDeleteImage()
  549. }
  550. })
  551. });
  552. bindDeleteImage()
  553. }
  554. // 删除图片按钮事件
  555. function bindDeleteImage() {
  556. $('.btn-option-img-trash').unbind('click').click(function () {
  557. let index = $(this).data('id')
  558. $('#c-option_preview_' + index).remove()
  559. // 赋值图片数据
  560. $('#c-options_img').html(JSON.stringify(getAllPreview()))
  561. });
  562. }
  563. // 重排选项名称
  564. function sortOptions() {
  565. $('dd[class="form-inline"]').each(function (index, ele) {
  566. console.log(option_name[index]);
  567. // 配置选项名并设为只读
  568. $($(this).find('.form-control')[0]).val(option_name[index]).attr('readonly', 'readonly');
  569. });
  570. }
  571. function unique(arr) {
  572. arr.sort();
  573. let newArr = [arr[0]];
  574. for (let i = 1; i < arr.length; i++) {
  575. if (arr[i] !== newArr[newArr.length - 1]) {
  576. newArr.push(arr[i]);
  577. }
  578. }
  579. return newArr;
  580. }
  581. function getAnswerType() {
  582. let kind = $('input[type="radio"][name="row[kind]"]:checked').val();
  583. return kind === 'MULTI' ? 'MULTI' : 'SINGLE';
  584. }
  585. function getAllPreview() {
  586. let options_img = []
  587. $('.option-preview').each(function (index, ele) {
  588. index = $(ele).data('id')
  589. options_img.push({
  590. key: getOptionNameByIndex(index),
  591. value: $(this).data('url')
  592. })
  593. })
  594. return options_img
  595. }
  596. function getOptionNameByIndex(index) {
  597. console.log('getOptionNameByIndex', index)
  598. return $($($('dd[class="form-inline"]')[index]).find('.form-control')[0]).val();
  599. }
  600. function previewHtml(id, value) {
  601. let cdnurl = Fast.api.cdnurl(value)
  602. return '<ul class="row list-inline plupload-preview option-preview-' + id + '" data-listidx="0" id="c-option_preview_' + id + '">' +
  603. '<li class="col-xs-3">' +
  604. '<a href="' + value + '" data-url="' + value + '" data-id="' + id + '" target="_blank" class="thumbnail option-preview">' +
  605. '<img src="' + cdnurl + '" class="img-responsive">' +
  606. '</a>' +
  607. '<a href="javascript:;" class="btn btn-danger btn-xs btn-trash btn-option-img-trash" data-id="' + id + '"><i class="fa fa-trash"></i></a>' +
  608. '</li>' +
  609. '</ul>';
  610. }
  611. function editorHtml(id, value) {
  612. return '<textarea id="' + id + '" class="form-control editor" name="' + id + '" value="' + value + '" ></textarea>';
  613. }
  614. function imageUploadHtml(id) {
  615. let html = '<div class="input-group" data-attr="image-upload">'
  616. html += '<input id="' + id + '" class="form-control" name="row[' + id + ']" size="300" type="text" >';
  617. html += '<div class="input-group-addon no-border no-padding">';
  618. html += '<span><button type="button" id="plupload-' + id + '" class="btn btn-danger plupload" data-input-id="' + id + '" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-' + id + '"><i class="fa fa-upload"></i> 上传</button></span>';
  619. html += '<span><button type="button" id="fachoose-image_url" class="btn btn-primary fachoose" data-input-id="' + id + '" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> 选择</button></span>';
  620. html += '</div>';
  621. html += '<span class="msg-box n-right" for="' + id + '"></span>';
  622. html += '</div>';
  623. html += '<ul class="row list-inline plupload-preview" id="p-' + id + '"></ul>';
  624. return html;
  625. }