Richtext.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="keywords" content="dongke,mes,ibossmes">
  6. <meta name="description" content="制造企业生产过程执行管理系统">
  7. <meta name="author" content="xuwei">
  8. <title>东科软件</title>
  9. <link rel="stylesheet" type="text/css" href="/plugins/easyui/themes/dongke/easyui.css">
  10. <link rel="stylesheet" type="text/css" href="/plugins/easyui/themes/icon.css">
  11. <link rel="stylesheet" type="text/css" href="/plugins/xeasyui/xuwell.css">
  12. <script type="text/javascript" src="/plugins/easyui/jquery.min.js"></script>
  13. <script type="text/javascript" src="/plugins/easyui/jquery.easyui.min.js"></script>
  14. <script type="text/javascript" src="/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>
  15. <link rel="shortcut icon" href="/img/logo.png" />
  16. <link rel="bookmark" href="/img/logo.png" />
  17. <link rel="stylesheet" type="text/css" href="/plugins/easyui/themes/dongke/easyui.css">
  18. <link rel="stylesheet" type="text/css" href="/plugins/easyui/themes/icon.css">
  19. <link rel="stylesheet" type="text/css" href="/plugins/xeasyui/xuwell.css">
  20. <script type="text/javascript" src="/plugins/easyui/jquery.easyui.min.js"></script>
  21. <script type="text/javascript" src="/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>
  22. <script type="text/javascript" src="/plugins/xeasyui/xuwell.js"></script>
  23. <link href="/plugins/xeasyui/toolbar.min.css" rel="stylesheet" />
  24. <link href="https://unpkg.com/@wangeditor/editor@latest/dist/css/style.css" rel="stylesheet">
  25. <style>
  26. .ddd {
  27. padding-top: 10px;
  28. margin: 0 20px;
  29. font-size: 20px
  30. }
  31. .inp {
  32. width: 100%;
  33. height: 32px;
  34. position: relative;
  35. /* 设置边框样式,以便更容易看到圆角效果 */
  36. border: 2px solid #ccc;
  37. /* 设置圆角半径 */
  38. border-radius: 10px; /* 你可以根据需要调整这个值 */
  39. }
  40. select {
  41. width: 100%;
  42. height: 32px;
  43. position: relative;
  44. background-color: #444;
  45. color: #fff;
  46. /* 设置边框样式,以便更容易看到圆角效果 */
  47. border: 2px solid #ccc;
  48. /* 设置圆角半径 */
  49. border-radius: 10px; /* 你可以根据需要调整这个值 */
  50. }
  51. .bbb {
  52. margin: 0 20px;
  53. font-size: 20px;
  54. width: 400px;
  55. border: 0;
  56. padding: 0 10px;
  57. background-color: #666;
  58. }
  59. .top {
  60. display: flex;
  61. justify-content: space-between; /* 可选,用于在元素之间添加空间,但在这个例子中可能不是必需的 */
  62. width: 100%; /* 确保 .top 容器占据其父容器的全部宽度 */
  63. }
  64. #editor—wrapper {
  65. border: 1px solid #ccc;
  66. z-index: 100; /* 按需定义 */
  67. height:100%;
  68. width:99%;
  69. margin:auto;
  70. }
  71. #toolbar-container {
  72. border-bottom: 1px solid #ccc;
  73. }
  74. #editor-container {
  75. height: 450px;
  76. }
  77. </style>
  78. </head>
  79. <body class="easyui-layout">
  80. <div id="toolbarLayout" data-options="border:false,region:'north',title:'',iconCls:'icon-grid'">
  81. <div style="min-height: 100vh; ">
  82. <div>
  83. <div class="top">
  84. <div class="ddd" style=" flex: 1;">
  85. <span>产品名称:<input id="input_name" class="inp" type="text"></span>
  86. </div>
  87. <div class="ddd" style=" flex: 1;">
  88. <span>产品型号:</span>
  89. <select id="modelSelect">
  90. <option disabled selected value="">请选择型号</option>
  91. </select>
  92. </div>
  93. </div>
  94. <div class="ddd">
  95. <span>参与人员:<input id="input_participants" class="inp" type="text"> </span>
  96. </div>
  97. <div class="ddd">
  98. <span>解决方式:<input id="input_solution" class="inp" type="text"> </span>
  99. </div>
  100. <div class="ddd">
  101. <span>解决效果:<input id="input_solutioneffect" class="inp" type="text"> </span>
  102. </div>
  103. <form enctype="multipart/form-data">
  104. <div id="presetFileName" class="ddd">
  105. <span id="filename"></span>
  106. <button type="button" class="ddd" style="padding-top:0; " onclick="deletefile()">删除</button>
  107. <button type="button" class="ddd" style="padding-top:0; " onclick="downfile()">下载已上传文件</button>
  108. </div>
  109. <div id="isopen" class="ddd">
  110. 上传附件:
  111. <input id="ff" type="file" style=" font-size: 20px" data-options="required:true,prompt:'',tipPosition:'bottom',buttonText:'选择文件',buttonAlign:'right',accept='*/*'">
  112. <button type="button" class="ddd" style="padding-top:0; " onclick="submitForm()">导入</button>
  113. <span style="color:red">上传附件后请点击导入按钮否则不会上传至服务器</span>
  114. </div>
  115. </form>
  116. </div>
  117. <div style=" padding-top:10px">
  118. <span class="ddd">问题: </span>
  119. <div id="editor—wrapper">
  120. <div id="toolbar-container"><!-- 工具栏 --></div>
  121. <div id="editor-container"><!-- 编辑器 --></div>
  122. <div id="editor-text-area" class="editor-text-area"></div>
  123. </div>
  124. </div>
  125. <div class="ddd" >
  126. <button type="button" class="ddd" style="padding-top: 0; " onclick="add()">提交/修改</button>
  127. </div>
  128. </div>
  129. </div>
  130. <script src="https://unpkg.com/@wangeditor/editor@latest/dist/index.js"></script>
  131. <script>
  132. //加载前调用
  133. $(document).ready(function () {
  134. getproductmodel();
  135. getQueryParam();
  136. });
  137. //创建富文本编辑器初始对象
  138. const E = window.wangEditor
  139. //语言切换(没用上 放着吧)
  140. const LANG = location.href.indexOf('lang=en') > 0 ? 'en' : 'zh-CN'
  141. E.i18nChangeLanguage(LANG)
  142. //创建初始项
  143. const editorConfig = {
  144. //自定义配置项
  145. MENU_CONF: {},
  146. //将画布上的内容添加到对象中
  147. onChange(editor) {
  148. const html = editor.getHtml()
  149. addsb.problem = html;
  150. },
  151. }
  152. //上传图片
  153. editorConfig.MENU_CONF['uploadImage'] = {
  154. server: 'Richtext.ashx?m=0',
  155. }
  156. // 上传视频
  157. editorConfig.MENU_CONF['uploadVideo'] = {
  158. server: 'Richtext.ashx?m=0',
  159. }
  160. //画布初始化
  161. const editor = E.createEditor({
  162. selector: '#editor-container',
  163. html: '<p><br></p>',
  164. config: editorConfig,
  165. mode: 'default',
  166. })
  167. //顶栏自定义
  168. const toolbarConfig = {}
  169. //顶栏配置项
  170. const toolbar = E.createToolbar({
  171. editor,
  172. selector: '#toolbar-container',
  173. config: toolbarConfig,
  174. mode: 'default', // or 'simple'
  175. })
  176. // 响应式数据:产品型号列表
  177. let models = [];
  178. /** 加载型号到 select 元素中 */
  179. const loadModelsToSelect=()=> {
  180. const select = document.getElementById('modelSelect');
  181. // 遍历模型数组并添加选项
  182. models.forEach(model => {
  183. const option = document.createElement('option');
  184. option.value = model.ID;
  185. option.textContent = model.GOODSCODE;
  186. select.appendChild(option);
  187. });
  188. // 设置默认选中的型号
  189. if (addsb.modelid) {
  190. const selectedOption = select.querySelector(`option[value="${addsb.modelid}"]`);
  191. if (selectedOption) {
  192. selectedOption.selected = true;
  193. }
  194. }
  195. // 监听选择变化
  196. select.addEventListener('change', function () {
  197. // 更新 addsb.model
  198. addsb.modelid = this.value;
  199. addsb.modelname = models.find(ex => ex.ID == addsb.modelid).GOODSCODE;
  200. });
  201. };
  202. //提交内容
  203. const addsb = {
  204. /**id*/
  205. id: '',
  206. /**项目名称*/
  207. name: '',
  208. /**产品型号id*/
  209. modelid: '',
  210. /**产品型号*/
  211. modelname: '',
  212. /**参与人员*/
  213. participants: '',
  214. /**问题*/
  215. problem: '',
  216. /**解决方式*/
  217. solution: '',
  218. /**解决效果*/
  219. solutioneffect: '',
  220. /**附件*/
  221. annex: ''
  222. };
  223. /**监视输入框*/
  224. $('#input_name, #input_participants,#input_solution,#input_solutioneffect').on('input', function () {
  225. const key = this.id.replace('input_', '');;
  226. addsb[key] = $(this).val();
  227. });
  228. /** 添加/修改按钮 */
  229. const add = () => {
  230. if (addsb.name == '') {
  231. alert('请填写产品名称');
  232. return;
  233. }
  234. if (addsb.model == '') {
  235. alert('请填写产品型号');
  236. return;
  237. }
  238. $.ajax({
  239. url: "Richtext.ashx?m=add",
  240. type: "POST",
  241. data: addsb,
  242. //要传递json时
  243. // contentType: "application/json; charset=utf-8",
  244. // data: JSON.stringify(formData),
  245. success: function (data) {
  246. history.pushState(null, null, '?id=' + parseInt(data, 10));
  247. getQueryParam();
  248. },
  249. error: function (xhr, status, error) {
  250. console.error("请求失败: " + error);
  251. }
  252. });
  253. }
  254. /** 上传附件 */
  255. const submitForm = () => {
  256. /**找到id为ff的文件上传框*/
  257. var fileInput = document.getElementById('ff');
  258. /**找到上传文件*/
  259. var file = fileInput.files[0];
  260. /**创建文件对象*/
  261. var formData = new FormData();
  262. formData.append('file', file);
  263. /**创建连接*/
  264. var xhr = new XMLHttpRequest();
  265. xhr.open('POST', '/mes/pc/intelligence/Richtext.ashx?m=0', true);
  266. /**发送文件*/
  267. xhr.send(formData);
  268. /**返回值赋值*/
  269. xhr.onload = function () {
  270. if (xhr.status === 200) {
  271. try {
  272. /**将JSON字符串解析为JavaScript对象 */
  273. var responseData = JSON.parse(xhr.response);
  274. /**检查errno是否为0,以确认请求成功 */
  275. if (responseData.errno === 0) {
  276. /**设置addsb.annex为响应中的url */
  277. addsb.annex = responseData.data.url;
  278. messager(true);
  279. } else {
  280. console.error('请求成功但发生错误', responseData.errno);
  281. messager(false);
  282. }
  283. } catch (e) {
  284. console.error('解析JSON失败', e);
  285. messager(false);
  286. }
  287. } else {
  288. console.error('请求失败', xhr.status);
  289. messager(false);
  290. }
  291. }
  292. };
  293. /**消息提示*/
  294. const messager = (type) => {
  295. $.messager.show({
  296. title: type ? '上传成功' :"上传失败",
  297. msg: type ?'文件成功上传至服务器':'文件上传服务器失败',
  298. showType: 'slide',
  299. style: {
  300. right: '',
  301. top: document.body.scrollTop + document.documentElement.scrollTop,
  302. bottom: ''
  303. }
  304. });
  305. }
  306. /** 获取产品型号 */
  307. const getproductmodel = () => {
  308. $.get("Richtext.ashx?m=getproductmodel", function (data) {
  309. var json = JSON.parse(data);
  310. models = json;
  311. loadModelsToSelect();
  312. })
  313. };
  314. /** 获取当前记录 */
  315. const getlibrary = async (libraryid) => {
  316. return new Promise((resolve, reject) => {
  317. $.ajax({
  318. url: "Richtext.ashx?m=get",
  319. type: "POST",
  320. data: { id: libraryid },
  321. dataType: "json",
  322. success: function (response) {
  323. if (response && response.length > 0) {
  324. const data = response[0];
  325. addsb.id = data.id;
  326. addsb.name = data.name;
  327. addsb.modelid = data.modelid;
  328. addsb.modelname = data.modelname;
  329. addsb.participants = data.participants;
  330. addsb.problem = data.problem;
  331. addsb.solution = data.solution;
  332. addsb.solutioneffect = data.solutioneffect;
  333. addsb.annex = data.annex;
  334. // 设置输入框的初始值
  335. input_name.value = addsb.name;
  336. input_participants.value = addsb.participants;
  337. input_solution.value = addsb.solution;
  338. input_solutioneffect.value = addsb.solutioneffect;
  339. //异步完成标识
  340. resolve();
  341. } else {
  342. reject(new Error("没有获取到有效的数据"));
  343. }
  344. },
  345. error: function (xhr, status, error) {
  346. reject(new Error("请求失败: " + error));
  347. }
  348. });
  349. });
  350. };
  351. /**获取url内的id */
  352. const getQueryParam = async () => {
  353. let libraryIdFound = false;
  354. let libraryPromise = null;
  355. // 获取URL的查询字符串部分
  356. var search = window.location.search.substring(1);
  357. // 将查询字符串分割成键值对数组
  358. var params = search.split("&");
  359. for (var i = 0; i < params.length; i++) {
  360. var val = params[i].split("=");
  361. // 如果找到了匹配的参数名,则返回其值
  362. if (val[0] == 'id') {
  363. libraryIdFound = true;
  364. libraryPromise = getlibrary(val[1]);
  365. break;
  366. }
  367. }
  368. if (libraryIdFound) {
  369. // 等待getlibrary完成
  370. await libraryPromise;
  371. }
  372. opendiv();
  373. loadModelsToSelect();
  374. };
  375. /**删除按钮 */
  376. const deletefile = () => {
  377. //文件重新赋值
  378. addsb.annex = '';
  379. /**上传附件 */
  380. let isopen = document.getElementById('isopen');
  381. //展示
  382. isopen.style.display = 'block';
  383. /**显示附件 */
  384. let presetFileName = document.getElementById('presetFileName');
  385. // 隐藏文件输入字段
  386. presetFileName.style.display = 'none';
  387. //调用删除附件(只是删除数据库,物理路径并未删除)
  388. $.ajax({
  389. url: "Richtext.ashx?m=deletefile",
  390. type: "POST",
  391. data: { id: addsb.id },
  392. })
  393. };
  394. /**下载附件 */
  395. const downfile = () => {
  396. var a = document.createElement("a");
  397. a.href = addsb.annex;
  398. a.download = addsb.annex.substr(addsb.annex.lastIndexOf('/') + 1);
  399. document.body.appendChild(a);
  400. a.click();
  401. document.body.removeChild(a);
  402. };
  403. /**判断是否开启div*/
  404. const opendiv = () => {
  405. /**上传附件 */
  406. let isopen = document.getElementById('isopen');
  407. /**显示附件 */
  408. let presetFileName = document.getElementById('presetFileName');
  409. //判断上传文档是否开启
  410. if (addsb.annex) {
  411. // 隐藏
  412. isopen.style.display = 'none';
  413. let filename = document.getElementById('filename');
  414. filename.innerHTML = '已上传文件: ' + addsb.annex.substr(addsb.annex.lastIndexOf('/') + 1);
  415. presetFileName.style.display = 'block';
  416. } else {
  417. presetFileName.style.display = 'none';
  418. isopen.style.display = 'block';
  419. }
  420. // 假设您已经有一个全局的编辑器实例变量 `editor`
  421. if (editor && typeof editor.setHtml === 'function') {
  422. // 设置编辑器的内容为从服务器返回的问题数据
  423. editor.setHtml(addsb.problem);
  424. }
  425. }
  426. </script>
  427. </body>
  428. </html >