question.js 29 KB

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