print_develop.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. var vm;
  2. $(document).ready(function () {
  3. vm = new Vue({
  4. el: '#app1',
  5. data: {
  6. PrintList: [],
  7. IsShowAnswer:0,
  8. CreateTime:formatTime(new Date(),"-",true),
  9. CardNumber:0,
  10. QRCodeImg:"https://kylx365-1253256735.file.myqcloud.com/web/xcode_a_180x180.png",
  11. NickName:serverurl4,
  12. PrintID:0,
  13. },
  14. methods: {
  15. getList: function (event) {
  16. $("#loading").css("display","flex");
  17. var param = {};
  18. param.IDSelect = serverurl1;
  19. var url = serverurl2;
  20. vm.IsShowAnswer = serverurl3;
  21. $.post("/apiData/" + url, param, function (data) {
  22. //console.log(data);
  23. var list = data.result.List;
  24. vm.CardNumber=list.length;
  25. //console.log(list);
  26. for (var i = 0; i < list.length; i++) {
  27. list[i].Content = changeStringToView(list[i].Content);
  28. if (vm.IsShowAnswer>=1) {
  29. var item2=list[i].Content.Field[2];
  30. if (item2) {
  31. list[i].HasField2 = true;
  32. for(var j=0;j<item2.length;j++){
  33. if (item2[j].Type=="image"){
  34. console.log(item2[j].Content);
  35. if (item2[j].Content.indexOf("baidu.com")>=0 || item2[j].Content.indexOf("bcebos.com")>=0){
  36. list[i].Content.Field[2][j].Type="imageSmall";
  37. }
  38. }
  39. }
  40. }
  41. else
  42. list[i].HasField2 = false;
  43. var item3=list[i].Content.Field[3];
  44. if (item3) {
  45. list[i].HasField3 = true;
  46. for(var j=0;j<item3.length;j++){
  47. if (item3[j].Type=="image"){
  48. console.log(item3[j].Content);
  49. if (item3[j].Content.indexOf("baidu.com")>=0 || item3[j].Content.indexOf("bcebos.com")>=0){
  50. list[i].Content.Field[3][j].Type="imageSmall";
  51. }
  52. }
  53. }
  54. }
  55. else
  56. list[i].HasField3 = false;
  57. }
  58. list[i].Index=i+1;
  59. }
  60. var result=[],resultTemp=[];
  61. for (var i=0;i<list.length;i++){
  62. resultTemp.push(list[i]);
  63. }
  64. result.push(resultTemp);
  65. vm.PrintList = result;
  66. var count=result[0].length;
  67. setTimeout(function(){
  68. result=[],resultTemp=[],tempX=0,tempY=0,b=false;
  69. for(var i=0;i<count;i++){
  70. var p = $("#item"+i);
  71. //console.log("i:"+i);
  72. var offset = p.offset();
  73. //console.log("offset::"+JSON.stringify(offset));
  74. //console.log("height:"+p.height());
  75. if (offset){
  76. //console.log(i+" x:"+offset.left+" y:"+offset.top);
  77. if (i>0 && tempX!=offset.left)
  78. b++;
  79. var bRow=2;
  80. if (vm.IsShowAnswer==3)
  81. bRow=1;
  82. if (i>0 && offset.top <= tempY && b>=bRow){
  83. result.push(resultTemp);
  84. resultTemp=[];
  85. b=0;
  86. }
  87. if (p.height()>960){
  88. list[i].ImageHeight="width:50%;";
  89. list[i].ImageHeight2="width:100%;";
  90. }
  91. else {
  92. list[i].ImageHeight = "auto;";
  93. list[i].ImageHeight2 = "auto;";
  94. }
  95. resultTemp.push(list[i]);
  96. tempX=offset.left;
  97. tempY=offset.top;
  98. }
  99. }
  100. result.push(resultTemp);
  101. vm.PrintList = result;
  102. //console.log(result);
  103. setTimeout(function(){
  104. $("#loading").css("display","none");
  105. $(".panelMain").css("visibility","visible");
  106. },200);
  107. vm.PrintID=data.result.PrintID;
  108. vm.QRCodeImg="https://miaguo-1253256735.file.myqcloud.com/MiaoguoPrint"+data.result.PrintID+".png";
  109. },5000);
  110. });
  111. },
  112. defaultImg: function (event) {
  113. setTimeout(function(){
  114. vm.QRCodeImg="https://miaguo-1253256735.file.myqcloud.com/MiaoguoPrint"+vm.PrintID+".png";
  115. },1000);
  116. }
  117. }
  118. });
  119. function init() {
  120. vm.getList();
  121. }
  122. init();
  123. function changeStringToView(field) {
  124. var result = {};
  125. result.Field = [[]];
  126. result.Images = [];
  127. for (var j = 0; j < field.length; j++) {
  128. if (j == 0) {
  129. if (field[j].ContentType == 0 && field[j].Content && field[j].Content.length > 0) {
  130. result.Tags = field[j].Content.toString().split(",");
  131. }
  132. else {
  133. result.Tags = [];
  134. }
  135. }
  136. else {
  137. if (field[j].ContentType == j && field[j].Content && field[j].Content.length > 0) {
  138. var arrResult = [], arrSoundMark = [];
  139. var str = field[j].Content.toString();
  140. str = DecryptUrl(str);
  141. str = str.replace(/\[读/g, "\n[读");
  142. str = str.replace(/\[图/g, "\n[图");
  143. str = str.replace(/\[\/读\]/g, "[\/读]\n");
  144. str = str.replace(/\[\/图\]/g, "[\/图]\n");
  145. str = str.replace(/\n\n\n/g, "\n\n");
  146. var arr = str.split("\n");
  147. for (var k = 0; k < arr.length; k++) {
  148. if (arr[k].indexOf("[图") >= 0 && arr[k].indexOf("[/图]") > 0) {
  149. var obj = {};
  150. obj.Type = "image";
  151. if (arr[k].indexOf("[图") >= 0) {
  152. obj.ContentServer = arr[k].substring(arr[k].indexOf("[图") + 3, arr[k].indexOf("[/图]"));
  153. const w = 650;
  154. if (obj.ContentServer.indexOf("w='") >= 0 && obj.ContentServer.indexOf("h='") >= 0) {
  155. obj.Width = obj.ContentServer.substring(obj.ContentServer.indexOf("w='") + 3, obj.ContentServer.indexOf("h='") - 2);
  156. obj.Height = obj.ContentServer.substring(obj.ContentServer.indexOf("h='") + 3, obj.ContentServer.indexOf("']"));
  157. obj.Height = Math.round((w * Number(obj.Height)) / Number(obj.Width));
  158. obj.Width = w;
  159. }
  160. else {
  161. obj.Width = "";
  162. obj.Height = "";
  163. }
  164. obj.ContentServer = obj.ContentServer.substring(obj.ContentServer.indexOf("]") + 1);
  165. obj.Content = obj.ContentServer;
  166. result.Images.push(obj.Content);
  167. }
  168. arrResult.push(obj);
  169. }
  170. else if ((arr[k].indexOf("[线]") >= 0 && arr[k].indexOf("[/线]") > 0) || (arr[k].indexOf("[光]") >= 0 && arr[k].indexOf("[/光]") > 0)) {
  171. var obj;
  172. var content = [], temp = arr[k];
  173. do {
  174. var num1 = temp.indexOf("[线]");
  175. var num2 = temp.indexOf("[光]");
  176. if (num1 >= 0 || num2 >= 0) {
  177. if ((num1 < num2 && num1 >= 0 && num2 >= 0) || (num1 >= 0 && num2 < 0)) {
  178. var temp1 = temp.substring(0, temp.indexOf("[线]"));
  179. if (temp1) {
  180. content.push({
  181. key: "normal",
  182. value: temp1,
  183. });
  184. }
  185. else {
  186. if (temp && temp.indexOf("[线]") < 0) {
  187. content.push({
  188. key: "normal",
  189. value: temp,
  190. });
  191. temp = "";
  192. }
  193. }
  194. }
  195. else if ((num1 > num2 && num1 >= 0 && num2 >= 0) || (num1 < 0 && num2 >= 0)) {
  196. var temp1 = temp.substring(0, temp.indexOf("[光]"));
  197. if (temp1) {
  198. content.push({
  199. key: "normal",
  200. value: temp1,
  201. });
  202. }
  203. else {
  204. if (temp && temp.indexOf("[光]") < 0) {
  205. content.push({
  206. key: "normal",
  207. value: temp,
  208. });
  209. temp = "";
  210. }
  211. }
  212. }
  213. else {
  214. content.push({
  215. key: "normal",
  216. value: temp,
  217. });
  218. temp = "";
  219. }
  220. }
  221. else {
  222. content.push({
  223. key: "normal",
  224. value: temp,
  225. });
  226. temp = "";
  227. }
  228. if (temp.length > 0 && ( num1 >= 0 || num2 >= 0 )) {
  229. if ((num1 < num2 && num1 >= 0 && num2 >= 0) || (num1 >= 0 && num2 < 0)) {
  230. temp = temp.substr(temp.indexOf("[线]") + 3);
  231. temp1 = temp.substring(0, temp.indexOf("[/线]"));
  232. if (temp1) {
  233. content.push({
  234. key: "line",
  235. value: temp1,
  236. });
  237. }
  238. temp = temp.substr(temp.indexOf("[/线]") + 4);
  239. }
  240. else if ((num1 > num2 && num1 >= 0 && num2 >= 0) || (num1 < 0 && num2 >= 0)) {
  241. temp = temp.substr(temp.indexOf("[光]") + 3);
  242. temp1 = temp.substring(0, temp.indexOf("[/光]"));
  243. if (temp1) {
  244. content.push({
  245. key: "highlighter",
  246. value: temp1,
  247. });
  248. }
  249. temp = temp.substr(temp.indexOf("[/光]") + 4);
  250. }
  251. else
  252. temp = "";
  253. }
  254. else
  255. temp = "";
  256. }
  257. while (temp.length > 0);
  258. for (var n = 0; n < content.length; n++)
  259. content[n].ChildID = n;
  260. obj = {};
  261. obj.Type = "line";
  262. obj.Content = content;
  263. arrResult.push(obj);
  264. }
  265. else if (arr[k].indexOf("[读") >= 0 && arr[k].indexOf("[/读]") > 0) {
  266. var obj = {};
  267. obj.Type = "sound";
  268. if (arr[k].indexOf("[读]") >= 0) {
  269. obj.Content = arr[k].substring(arr[k].indexOf("[读]") + 3, arr[k].indexOf("[/读]"));
  270. }
  271. else {
  272. var tempIndex = arr[k].indexOf("\']") + 2;
  273. obj.Content = arr[k].substring(tempIndex, arr[k].indexOf("[/读]"));
  274. obj.SoundMark = arr[k].substring(arr[k].indexOf("src='") + 5, arr[k].indexOf("']"));
  275. ;
  276. }
  277. arrResult.push(obj);
  278. }
  279. else if (arr[k].indexOf("[音") >= 0 && arr[k].indexOf("[/音]") > 0) {
  280. var obj = {};
  281. obj.Type = "recorder";
  282. var tempIndex = arr[k].indexOf("\']") + 2;
  283. //obj.Content = arr[k].substring(tempIndex, arr[k].indexOf("[/音]"));
  284. obj.SoundMark = arr[k].substring(arr[k].indexOf("url='") + 5, arr[k].indexOf("']"));
  285. arrResult.push(obj);
  286. }
  287. else if (arr[k] != "") {
  288. var obj = {};
  289. obj.Type = "normal";
  290. obj.Content = arr[k];
  291. arrResult.push(obj);
  292. }
  293. else if (k > 0 && arr[k] == "") {
  294. var obj = {};
  295. obj.Type = "br";
  296. obj.Content = "";
  297. arrResult.push(obj);
  298. }
  299. var obj = {};
  300. obj.Type = "return";
  301. obj.Content = "";
  302. arrResult.push(obj);
  303. }
  304. //去掉前回车换行
  305. while (arrResult[0].Type == "return"
  306. || arrResult[0].Type == "br") {
  307. arrResult.shift();
  308. if (arrResult.length == 0)
  309. break;
  310. }
  311. //去掉后回车换行
  312. for (var i = arrResult.length - 1; i >= 0; i--) {
  313. if (arrResult[i].Type == "return"
  314. || arrResult[i].Type == "br")
  315. arrResult.pop();
  316. else {
  317. break;
  318. }
  319. }
  320. for (var i = 0; i < arrResult.length; i++) {
  321. arrResult[i].ID = i;
  322. }
  323. result.Field.push(arrResult);
  324. }
  325. else {
  326. result.Field.push([]);
  327. }
  328. }
  329. }
  330. return result;
  331. }
  332. function EncryptUrl(str) {
  333. if (str.constructor == Array) {
  334. if (str.length > 0)
  335. str = str.join(",");
  336. else
  337. str = "";
  338. }
  339. if (str) {
  340. str = str.replace(/baidu.com/g, "#####1#####");
  341. str = str.replace(/iciba.com/g, "#####2#####");
  342. str = str.replace(/https:\/\/pinyin.kylx365.com\/sounds/g, "#####3#####");
  343. str = str.replace(/https:\/\/pinyin-1253256735.file.myqcloud.com/g, "#####3#####");
  344. str = str.replace(/https:\/\/miaguo-1253256735.file.myqcloud.com/g, "#####4#####");
  345. }
  346. if (str.substr(0, 1) == "\n")
  347. str = str.substr(1);
  348. return str;
  349. }
  350. function DecryptUrl(str) {
  351. if (str.constructor == Array) {
  352. if (str.length > 0)
  353. str = str.join(",");
  354. else
  355. str = "";
  356. }
  357. if (str) {
  358. str = str.replace(/#####1#####/g, "baidu.com");
  359. str = str.replace(/#####2#####/g, "iciba.com");
  360. str = str.replace(/#####3#####/g, "https://pinyin-1253256735.file.myqcloud.com");
  361. str = str.replace(/#####4#####/g, "https://miaguo-1253256735.file.myqcloud.com");
  362. }
  363. return str;
  364. }
  365. });