question.js 29 KB

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