bank-manage.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. const RegStr = "^$.*+-?=!:|\\/()[]{}"
  2. Vue.createApp({
  3. mounted() {
  4. $.get("/bank/manage/", {info: "yes"}, res => {
  5. if (res.success) {
  6. let tmp = [];
  7. for (let k in res.data.full) tmp.push(res.data.full[k]);
  8. this.full_data_raw = this.full_data_show = tmp;
  9. this.unresolved_data_raw = this.unresolved_data_show = res.data.unresolved;
  10. this.error_data_raw = this.error_data_show = res.data.error;
  11. } else alert("数据获取失败");
  12. });
  13. },
  14. delimiters: ["{[", "]}"],
  15. data() {
  16. return {
  17. which_cur: 0,
  18. full_insert_idx: 1,
  19. full_condition: "",
  20. full_data_raw: [],
  21. full_data_show: [],
  22. unresolved_condition: "",
  23. unresolved_data_raw: [],
  24. unresolved_data_show: [],
  25. error_data_raw: [],
  26. error_data_show: [],
  27. icon_view: {show: false, which: -1, index: -1, name: "", url: "", file: null}
  28. }
  29. },
  30. methods: {
  31. _getRegStr(str) {
  32. let arr = [];
  33. for (let it in str) {
  34. if (RegStr.includes(str[it])) arr.push("\\" + str[it]);
  35. else arr.push(str[it]);
  36. }
  37. return ".*" + arr.join(".*") + ".*";
  38. },
  39. _strLike(short, long) {
  40. if (short === "") return true;
  41. let ptn = new RegExp(this._getRegStr(short), "i");
  42. return ptn.test(long);
  43. },
  44. _json2str(obj = {}, keys = []) {
  45. let arr = [];
  46. for (let key in obj) if (keys.includes(key)) arr.push(key + ": " + obj[key]);
  47. return "{" + arr.join(", ") + "}";
  48. },
  49. fullFind(cond = "") {
  50. this.full_data_show = this.full_data_raw.filter(
  51. item => this._strLike(cond, item.short)
  52. || this._strLike(cond, item.bin)
  53. || this._strLike(cond, item.name)
  54. );
  55. },
  56. unresolvedFind(cond = "") {
  57. this.unresolved_data_show = this.unresolved_data_raw.filter(
  58. item => this._strLike(cond, item.short)
  59. || this._strLike(cond, item.number)
  60. || this._strLike(cond, item.name)
  61. );
  62. },
  63. fullDelete(index) {
  64. let tar = this.full_data_show[index];
  65. let msg = "是否确定删除:\n" + this._json2str(tar, ["short", "name"]);
  66. if (confirm(msg)) {
  67. this.full_data_raw = this.full_data_raw.filter(ele => ele.short !== tar.short);
  68. this.full_data_show = this.full_data_show.filter(ele => ele.short !== tar.short);
  69. }
  70. },
  71. fullChange(index, byUser = true) {
  72. let isInsert = true, tar = this.full_data_show[index];
  73. if (byUser && tar.short.startsWith("__Need")) return alert("请修改新增内容的<简写>字段,并确保其唯一");
  74. for (let i = 0; i < this.full_data_raw.length; i++) {
  75. if (this.full_data_raw[i]["short"] === tar.short) {
  76. this.full_data_raw[i] = tar;
  77. isInsert = false;
  78. break;
  79. }
  80. }
  81. if (isInsert) this.full_data_raw[tar.short] = tar;
  82. },
  83. fullNew() {
  84. this.full_data_show.unshift(
  85. {bin: "", name: "", short: "__NeedModify-" + this.full_insert_idx++, icon: ""}
  86. );
  87. },
  88. fullUpdate() {
  89. let data = {};
  90. this.full_data_raw.forEach(ele => {
  91. if (ele.short !== "" && ele.name !== "") data[ele.short] = ele;
  92. });
  93. $.post("/bank/manage/", {which: "full", opt: "update", data: JSON.stringify(data)}, res => {
  94. if (!res.success) alert(res.message);
  95. else alert("更新成功");
  96. });
  97. },
  98. fullPersist() {
  99. $.post("/bank/manage/", {which: "full", opt: "persist"}, res => {
  100. if (!res.success) alert(res.message);
  101. else alert("写入文件成功");
  102. });
  103. },
  104. iconView(which, index) {
  105. let item = which === 0 ? this.full_data_show[index] : this.unresolved_data_show[index],
  106. icon = item.icon === "" ? "A-Fail" : item.icon;
  107. this.icon_view.name = item.icon;
  108. this.icon_view.url = "/static/bank/" + icon + ".png";
  109. this.icon_view.which = which;
  110. this.icon_view.index = index;
  111. this.icon_view.show = true;
  112. },
  113. iconViewClose() {
  114. this.icon_view.show = false;
  115. this.icon_view.which = -1;
  116. this.icon_view.index = -1;
  117. this.icon_view.name = "";
  118. this.icon_view.url = "";
  119. this.icon_view.file = null;
  120. },
  121. iconFileChange(event) {
  122. let file = event.target.files[0];
  123. if (file.type !== "image/png") return alert("icon仅支持png");
  124. if (file.size > 1024 * 1024) return alert("图像大小超过1M");
  125. let reader = new FileReader();
  126. reader.readAsDataURL(file);
  127. reader.onload = e => this.icon_view.url = e.target.result;
  128. this.icon_view.file = file;
  129. },
  130. iconUpload() {
  131. if (this.icon_view.file === null || this.icon_view.name === "")
  132. return alert("请选择文件并填写名称")
  133. let formData = new FormData();
  134. formData.append("which", "icon");
  135. formData.append("opt", "upload");
  136. formData.append("name", this.icon_view.name);
  137. formData.append("icon", this.icon_view.file);
  138. $.post({
  139. url: "/bank/manage/",
  140. processData: false,
  141. contentType: false,
  142. data: formData,
  143. success: res => {
  144. if (res.success) {
  145. if (this.icon_view.which === 0) { // full
  146. this.full_data_show[this.icon_view.index].icon = this.icon_view.name;
  147. this.fullChange(this.icon_view.index, false);
  148. } else { // unresolved
  149. this.unresolved_data_show[this.icon_view.index].icon = this.icon_view.name;
  150. this.unresolvedChange(this.icon_view.index);
  151. }
  152. alert("icon上传成功");
  153. this.iconViewClose();
  154. } else alert(res.message);
  155. },
  156. error: err => alert("发生错误:" + err)
  157. });
  158. },
  159. unresolvedChange(index) {
  160. let tar = this.unresolved_data_show[index];
  161. for (let i = 0; i < this.unresolved_data_raw.length; i++) {
  162. if (this.unresolved_data_raw[i]["short"] === tar.short) {
  163. this.unresolved_data_raw[i] = tar;
  164. break;
  165. }
  166. }
  167. },
  168. unresolvedUpdate(index) {
  169. let tar = this.unresolved_data_show[index];
  170. }
  171. },
  172. computed: {
  173. isFullDataEmpty() {
  174. return $.isEmptyObject(this.full_data_show);
  175. }
  176. }
  177. }).mount("#root");