define(['jquery', 'bootstrap', 'backend', 'table', 'form','editable'], function ($, undefined, Backend, Table, Form) { var Controller = { index: function () { $(".btn-add").data("area",["100%","100%"]); $(".btn-edit").data("area",["100%","100%"]); // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'product/index' + location.search, add_url: 'product/add', edit_url: 'product/edit', del_url: 'product/del', multi_url: 'product/multi', import_url: 'product/import', table: 'product', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', fixedColumns: true, fixedRightNumber: 1, columns: [ [ {checkbox: true}, // {field: 'id', title: __('Id')}, {field: 'material', title: __('Material'), operate: 'LIKE'}, {field: 'height', title: __('Height'),operate: 'LIKE'}, {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.normal}, {field: 'time', title: __('Time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true}, {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} ] ] }); table.on('post-body.bs.table',function(){ $(".btn-editone").data("area",["100%","100%"]); }); // 为表格绑定事件 Table.api.bindevent(table); }, add: function () { $("#c-batch").keydown(function(e){ var key = e.which; if (key == 13) { $.ajax({ type:"POST", url:"product/ajax", data:{ bach:$("#c-batch").val() }, success(res){ $("#c-time").val(res.create); $("#c-audit").val(res.examine_name); $("#c-pname").val(res.name); } }); return false; } }); $("#wuliao").keydown( function (e) { var key = e.which; if (key == 13) { var str = ''; $.ajax({ type: "POST", url: "product/get_formula", data: { formula: $("#wuliao").val(), }, success(res) { str += ""; str += ""; str += ""; str += ''; $("#table").append(str); $("#wuliao").val(''); if(res.error === 1){ Layer.confirm("此物料不在配方中,请确认!"); //语音播报 var msg = new SpeechSynthesisUtterance("此物料不在配方中,请确认!"); window.speechSynthesis.speak(msg); } } }); return false; } }); $(document).on('click','.del',function () { $(this).parent().parent().remove(); }); $('input').keydown( function (e) { let key = e.which; if (key == 13) { return false; } }); /** * 播报 * @param {Object} text 播放内容 */ startSpeech = (text)=>{ const speech = new SpeechSynthesisUtterance() // 设置播放内容 speech.text = text // 设置话语的音调(0-2 默认1,值越大越尖锐,越低越低沉) speech.pitch = 0.8 // 设置说话的速度(0.1-10 默认1,值越大语速越快,越小语速越慢) speech.rate = 1 // 设置说话的音量 speech.volume = 10 // 设置播放语言 speech.lang = 'zh-CN' // 播放结束后调用 speech.onend = (event)=>{ } // 加入播放队列 window.speechSynthesis.speak(speech); }; /** * 停止播报,停止所有播报队列里面的语音 */ stopSpeech = () => { window.speechSynthesis.cancel(); }; Controller.api.bindevent(); }, edit: function () { Controller.api.bindevent(); }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]")); } }, }; return Controller; });