From bb1e35273a266953d1b5b890aef83be8666e8a5a Mon Sep 17 00:00:00 2001 From: Lei OT Date: Tue, 22 Aug 2023 16:08:51 +0800 Subject: [PATCH] conf: eslint: "no-unreachable", "array-callback-return" --- .eslintrc.json | 6 ++-- package-lock.json | 66 ++++++++++++++++++++++++++++++++++ package.json | 2 ++ src/config.js | 2 +- src/stores/DashboardStore.js | 1 + src/stores/SaleStore.js | 12 ++++--- src/utils/commons.js | 1 + src/views/Credit_card_bill.jsx | 11 ++---- src/views/Sale.jsx | 13 ++----- 9 files changed, 87 insertions(+), 27 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 6980840..4c71145 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -25,13 +25,12 @@ "no-prototype-builtins": [1], "prefer-const": [1], // "new-cap": [1], - "array-callback-return": [1], "semi": [ "error", "always" ], "camelcase": [ - 1, + 0, { // "allow": ["_store$"], "ignoreImports": true, @@ -39,6 +38,7 @@ } ], "no-unused-vars": [1], - "spaced-comment": [1] + "spaced-comment": [1], + "no-unreachable":"off" } } diff --git a/package-lock.json b/package-lock.json index 7b60015..466b797 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,8 @@ "xlsx": "https://cdn.sheetjs.com/xlsx-0.18.11/xlsx-0.18.11.tgz" }, "devDependencies": { + "@types/react": "^18.2.20", + "@types/react-dom": "^18.2.7", "eslint": "^8.46.0", "eslint-config-prettier": "^9.0.0", "eslint-config-standard": "^17.1.0", @@ -4840,6 +4842,12 @@ "resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.7.2.tgz", "integrity": "sha512-KufADq8uQqo1pYKVIYzfKbJfBAc0sOeXqGbFaSpv8MRmC/zXgowNZmFcbngndGk922QDmOASEXUZCaY48gs4cg==" }, + "node_modules/@types/prop-types": { + "version": "15.7.5", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz", + "integrity": "sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==", + "dev": true + }, "node_modules/@types/q": { "version": "1.5.5", "resolved": "https://registry.npmjs.org/@types/q/-/q-1.5.5.tgz", @@ -4855,6 +4863,26 @@ "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.4.tgz", "integrity": "sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==" }, + "node_modules/@types/react": { + "version": "18.2.20", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.2.20.tgz", + "integrity": "sha512-WKNtmsLWJM/3D5mG4U84cysVY31ivmyw85dE84fOCk5Hx78wezB/XEjVPWl2JTZ5FkEeaTJf+VgUAUn3PE7Isw==", + "dev": true, + "dependencies": { + "@types/prop-types": "*", + "@types/scheduler": "*", + "csstype": "^3.0.2" + } + }, + "node_modules/@types/react-dom": { + "version": "18.2.7", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.2.7.tgz", + "integrity": "sha512-GRaAEriuT4zp9N4p1i8BDBYmEyfo+xQ3yHjJU4eiK5NDa1RmUZG+unZABUTK4/Ox/M+GaHwb6Ow8rUITrtjszA==", + "dev": true, + "dependencies": { + "@types/react": "*" + } + }, "node_modules/@types/resize-observer-browser": { "version": "0.1.7", "resolved": "https://registry.npmmirror.com/@types/resize-observer-browser/-/resize-observer-browser-0.1.7.tgz", @@ -4873,6 +4901,12 @@ "resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.0.tgz", "integrity": "sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==" }, + "node_modules/@types/scheduler": { + "version": "0.16.3", + "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.3.tgz", + "integrity": "sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ==", + "dev": true + }, "node_modules/@types/semver": { "version": "7.3.13", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.3.13.tgz", @@ -24062,6 +24096,12 @@ "resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.7.2.tgz", "integrity": "sha512-KufADq8uQqo1pYKVIYzfKbJfBAc0sOeXqGbFaSpv8MRmC/zXgowNZmFcbngndGk922QDmOASEXUZCaY48gs4cg==" }, + "@types/prop-types": { + "version": "15.7.5", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz", + "integrity": "sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==", + "dev": true + }, "@types/q": { "version": "1.5.5", "resolved": "https://registry.npmjs.org/@types/q/-/q-1.5.5.tgz", @@ -24077,6 +24117,26 @@ "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.4.tgz", "integrity": "sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==" }, + "@types/react": { + "version": "18.2.20", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.2.20.tgz", + "integrity": "sha512-WKNtmsLWJM/3D5mG4U84cysVY31ivmyw85dE84fOCk5Hx78wezB/XEjVPWl2JTZ5FkEeaTJf+VgUAUn3PE7Isw==", + "dev": true, + "requires": { + "@types/prop-types": "*", + "@types/scheduler": "*", + "csstype": "^3.0.2" + } + }, + "@types/react-dom": { + "version": "18.2.7", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.2.7.tgz", + "integrity": "sha512-GRaAEriuT4zp9N4p1i8BDBYmEyfo+xQ3yHjJU4eiK5NDa1RmUZG+unZABUTK4/Ox/M+GaHwb6Ow8rUITrtjszA==", + "dev": true, + "requires": { + "@types/react": "*" + } + }, "@types/resize-observer-browser": { "version": "0.1.7", "resolved": "https://registry.npmmirror.com/@types/resize-observer-browser/-/resize-observer-browser-0.1.7.tgz", @@ -24095,6 +24155,12 @@ "resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.0.tgz", "integrity": "sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==" }, + "@types/scheduler": { + "version": "0.16.3", + "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.3.tgz", + "integrity": "sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ==", + "dev": true + }, "@types/semver": { "version": "7.3.13", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.3.13.tgz", diff --git a/package.json b/package.json index 0886e91..9ae7968 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,8 @@ ] }, "devDependencies": { + "@types/react": "^18.2.20", + "@types/react-dom": "^18.2.7", "eslint": "^8.46.0", "eslint-config-prettier": "^9.0.0", "eslint-config-standard": "^17.1.0", diff --git a/src/config.js b/src/config.js index 02b6d3c..433f879 100644 --- a/src/config.js +++ b/src/config.js @@ -2,4 +2,4 @@ import React from "react"; export const stores_Context = React.createContext(); export const DATE_FORMAT = "YYYY-MM-DD"; -export const HT_HOST = process.env.NODE_ENV == "production" ? "https://p9axztuwd7x8a7.mycht.cn" : "http://202.103.68.100:890"; \ No newline at end of file +export const HT_HOST = process.env.NODE_ENV === "production" ? "https://p9axztuwd7x8a7.mycht.cn" : "http://202.103.68.100:890"; diff --git a/src/stores/DashboardStore.js b/src/stores/DashboardStore.js index 1c7069b..8930d63 100644 --- a/src/stores/DashboardStore.js +++ b/src/stores/DashboardStore.js @@ -141,6 +141,7 @@ class DashboardStore { mobile_deal: item.YDOrderNumSUC + " / " + item.OrderNumSUC + " (" + (item.OrderNumSUCRate * 100).toFixed(1) + "%)", mobile_gross: item.YDML + " / " + item.ML + " (" + (item.MLRate * 100).toFixed(1) + "%)", }); + return item; }); runInAction(() => { this.mobile_data.data = table_data; diff --git a/src/stores/SaleStore.js b/src/stores/SaleStore.js index e890d39..5e29814 100644 --- a/src/stores/SaleStore.js +++ b/src/stores/SaleStore.js @@ -126,7 +126,7 @@ class SaleStore { .then(json => { if (!comm.empty(json.result2) && !comm.empty(date_moment.start_date_cp)) { } else { - if (this.active_tab_key == "All") { + if (this.active_tab_key === "All") { result.columns = [ { title: "", @@ -169,7 +169,7 @@ class SaleStore { }, ]; result.dataSource = json.result1; - } else if (this.active_tab_key == "ResponseRateByWL") { + } else if (this.active_tab_key === "ResponseRateByWL") { result.columns = [ { title: "", @@ -222,7 +222,7 @@ class SaleStore { }, ]; result.dataSource = json.result1; - } else if (this.active_tab_key == "ResponseRateWhatsApp") { + } else if (this.active_tab_key === "ResponseRateWhatsApp") { result.columns = [ { title: "", @@ -286,6 +286,7 @@ class SaleStore { const type_name_arr = []; json.result1.map(item => { type_name_arr[item.SubTypeSN] = { SubTypeSN: item.SubTypeSN, SubTypeName: item.SubTypeName }; + return item; }); const type_data = []; @@ -293,7 +294,7 @@ class SaleStore { for (const item of json.result1) { const op_sn = "OP_" + item.OPI_SN; // 顾问的SN - const items = json.result1.filter(d => d.OPI_SN == item.OPI_SN); // 筛选出有当前顾问的记录 + const items = json.result1.filter(d => String(d.OPI_SN) === String(item.OPI_SN)); // 筛选出有当前顾问的记录 const total_data_value = items.length ? items.reduce((a, b) => a + b.COLI_YJLY, 0) : ""; // 记录累加 if (comm.empty(type_data[op_sn])) { type_data[op_sn] = [{ key: item.OPI_SN }, { T_name: item.OPI_Name }, { T_total: total_data_value }]; @@ -308,6 +309,7 @@ class SaleStore { }) ) ); + return item; }); result.columns.push( { title: "顾问", children: [{ title: "", dataIndex: "T_name", render: (text, record) => {text} }] }, @@ -322,6 +324,7 @@ class SaleStore { children: [{ title: total_data_value, dataIndex: data_index }], sorter: (a, b) => b[data_index] - a[data_index], }); + return item; }); result.dataSource = type_data_arr; } @@ -400,6 +403,7 @@ class SaleStore { } else { type_data[subtype_sn].data.push(item); } + return item; }); result.dataSource = Object.values(type_data); } diff --git a/src/utils/commons.js b/src/utils/commons.js index d5fd7cb..952920f 100644 --- a/src/utils/commons.js +++ b/src/utils/commons.js @@ -162,6 +162,7 @@ export function empty(a) { if (Array.prototype.isPrototypeOf(a) && a.length === 0) return true; // 检验空数组 if (Object.prototype.isPrototypeOf(a) && Object.keys(a).length === 0) return true; // 检验空对象 return false; + // return [Object, Array].includes((obj || {}).constructor) && !Object.entries((obj || {})).length; } export function prepareUrl(url) { diff --git a/src/views/Credit_card_bill.jsx b/src/views/Credit_card_bill.jsx index 76aeba4..5d0b09c 100644 --- a/src/views/Credit_card_bill.jsx +++ b/src/views/Credit_card_bill.jsx @@ -226,15 +226,8 @@ const Credit_card_bill = () => { }; // 格式化数据,饼图只支持数字模式 - const format_data_for_pie = data => { - const result_arr = []; - if (!comm.empty(data)) { - data.map(item => { - item.cb_usd_number = parseFloat(item.cb_usd.replace(/,/g, "")); - result_arr.push(item); - }); - } - return result_arr; + const format_data_for_pie = (data = []) => { + return data.map(item => ({...item, cb_usd_number: parseFloat(item.cb_usd.replace(/,/g, ""))})); }; const credit_card_bills = !comm.empty(credit_card_data.data) ? format_data_detail(credit_card_data.data) : format_data_detail([]); diff --git a/src/views/Sale.jsx b/src/views/Sale.jsx index b829bf5..471c1ec 100644 --- a/src/views/Sale.jsx +++ b/src/views/Sale.jsx @@ -47,15 +47,8 @@ const Sale = () => { }; // 格式化数据,饼图只支持数字模式 - const format_data_for_pie = data => { - const result_arr = []; - if (!comm.empty(data)) { - data.map(item => { - item.COLI_ML_number = comm.price_to_number(item.COLI_ML); - result_arr.push(item); - }); - } - return result_arr; + const format_data_for_pie = (data = []) => { + return data.map(item => ({...item, COLI_ML_number: comm.price_to_number(item.COLI_ML)})); }; const pie_config = { @@ -249,7 +242,7 @@ const Sale = () => { - {sale_store.active_tab_key == "All" ? : ""} + {sale_store.active_tab_key === "All" ? : ""}