@kyfe/ks-query-table 0.0.21 → 0.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.bitmap +38 -0
- package/.editorconfig +5 -0
- package/.env.dev +2 -0
- package/.env.gray +2 -0
- package/.env.prod +2 -0
- package/.env.stg +3 -0
- package/.env.uat +2 -0
- package/.eslintignore +1 -0
- package/.eslintrc.js +25 -0
- package/.gitmodules +4 -0
- package/.prettierrc +11 -0
- package/README.md +15 -0
- package/babel.config.js +10 -0
- package/build-apm.sh +9 -0
- package/build.sh +16 -0
- package/config/index.js +20 -0
- package/jsconfig.json +7 -0
- package/kuasheng-sdk/index.js +80 -0
- package/kuasheng-sdk/lib/assets.js +304 -0
- package/kuasheng-sdk/lib/context.js +199 -0
- package/kuasheng-sdk/lib/layout.js +346 -0
- package/kuasheng-sdk/lib/location.js +46 -0
- package/kuasheng-sdk/lib/media.js +342 -0
- package/kuasheng-sdk/lib/navigation.js +30 -0
- package/kuasheng-sdk/lib/request.js +76 -0
- package/kuasheng-sdk/lib/system.js +190 -0
- package/kuasheng-sdk/lib/userinfo.js +98 -0
- package/kuasheng-sdk/util/check.js +102 -0
- package/kuasheng-sdk/util/config.js +47 -0
- package/kuasheng-sdk/util/device.js +25 -0
- package/kuasheng-sdk/util/error.js +19 -0
- package/kuasheng-sdk/util/funtional.js +153 -0
- package/kuasheng-sdk/util/mixin.js +36 -0
- package/kuasheng-sdk/util/requestUtil.js +41 -0
- package/kuasheng-sdk/util/response.js +33 -0
- package/kuasheng-sdk/util/warn.js +35 -0
- package/kuasheng-ui/CHANGELOG.md +9 -0
- package/kuasheng-ui/components/card.vue +57 -0
- package/kuasheng-ui/components/ks-area-select/README.md +43 -0
- package/kuasheng-ui/components/ks-area-select/area-picker.vue +554 -0
- package/kuasheng-ui/components/ks-area-select/area-search.vue +363 -0
- package/kuasheng-ui/components/ks-area-select/areas-pop.vue +56 -0
- package/kuasheng-ui/components/ks-area-select/common.js +183 -0
- package/kuasheng-ui/components/ks-area-select/index.vue +355 -0
- package/kuasheng-ui/components/ks-area-select/mixins.js +216 -0
- package/kuasheng-ui/components/ks-area-single-select/README.md +50 -0
- package/kuasheng-ui/components/ks-area-single-select/hot-city.js +45 -0
- package/kuasheng-ui/components/ks-area-single-select/index.vue +324 -0
- package/kuasheng-ui/components/ks-calendar/index.vue +269 -0
- package/kuasheng-ui/components/ks-call-phone/call-tips.vue +70 -0
- package/kuasheng-ui/components/ks-call-phone/call.vue +178 -0
- package/kuasheng-ui/components/ks-call-phone/index.js +48 -0
- package/kuasheng-ui/components/ks-call-phone/index.vue +131 -0
- package/kuasheng-ui/components/ks-call-phone//345/221/274/345/217/253/347/273/204/344/273/266.md +0 -0
- package/kuasheng-ui/components/ks-date-picker/README.md +23 -0
- package/kuasheng-ui/components/ks-date-picker/date-picker-bottom.vue +123 -0
- package/kuasheng-ui/components/ks-date-picker/date-picker-dropdown.vue +80 -0
- package/kuasheng-ui/components/ks-date-picker/date-picker-right.vue +87 -0
- package/kuasheng-ui/components/ks-date-picker/date-picker-top.vue +88 -0
- package/kuasheng-ui/components/ks-date-picker/date-picker.js +15 -0
- package/kuasheng-ui/components/ks-date-picker/date-range-select.vue +92 -0
- package/kuasheng-ui/components/ks-date-picker/date-select.vue +65 -0
- package/kuasheng-ui/components/ks-date-picker/date-week-month.vue +131 -0
- package/kuasheng-ui/components/ks-date-picker/index.js +12 -0
- package/kuasheng-ui/components/ks-date-picker/mixin.js +92 -0
- package/kuasheng-ui/components/ks-date-picker/month-range-select.vue +129 -0
- package/kuasheng-ui/components/ks-date-picker/month-select.vue +85 -0
- package/kuasheng-ui/components/ks-date-picker/quarter-select.vue +94 -0
- package/kuasheng-ui/components/ks-date-picker/style.less +121 -0
- package/kuasheng-ui/components/ks-date-picker/utils.js +109 -0
- package/kuasheng-ui/components/ks-date-picker/week-select.vue +99 -0
- package/kuasheng-ui/components/ks-decrypt/index.vue +159 -0
- package/kuasheng-ui/components/ks-employee/README.md +78 -0
- package/kuasheng-ui/components/ks-employee/employee-input.vue +173 -0
- package/kuasheng-ui/components/ks-employee/employee-list.vue +662 -0
- package/kuasheng-ui/components/ks-employee/employee-popup.vue +197 -0
- package/kuasheng-ui/components/ks-employee/employee-search.vue +250 -0
- package/kuasheng-ui/components/ks-employee/employee-selected.vue +173 -0
- package/kuasheng-ui/components/ks-employee/index.js +17 -0
- package/kuasheng-ui/components/ks-employee/package-lock.json +5 -0
- package/kuasheng-ui/components/ks-employee/package.json +15 -0
- package/kuasheng-ui/components/ks-employee/yarn.lock +4 -0
- package/kuasheng-ui/components/ks-field-money/index.js +8 -0
- package/kuasheng-ui/components/ks-field-money/index.vue +212 -0
- package/kuasheng-ui/components/ks-field-money/package.json +11 -0
- package/kuasheng-ui/components/ks-field-money/utils.js +65 -0
- package/kuasheng-ui/components/ks-field-money//351/207/221/351/242/235/350/275/254/346/215/242/345/231/250.md +0 -0
- package/kuasheng-ui/components/ks-history-search/history-input.vue +131 -0
- package/kuasheng-ui/components/ks-history-search/history-list.vue +188 -0
- package/kuasheng-ui/components/ks-history-search/img/delete.png +0 -0
- package/kuasheng-ui/components/ks-history-search/index.js +9 -0
- package/kuasheng-ui/components/ks-history-search/index.vue +125 -0
- package/kuasheng-ui/components/ks-history-search/package-lock.json +5 -0
- package/kuasheng-ui/components/ks-history-search/package.json +15 -0
- package/kuasheng-ui/components/ks-history-search/utils.js +35 -0
- package/kuasheng-ui/components/ks-input-search/index.vue +106 -0
- package/kuasheng-ui/components/ks-list/index.vue +75 -0
- package/kuasheng-ui/components/ks-loading/index.js +16 -0
- package/kuasheng-ui/components/ks-month/index.vue +47 -0
- package/kuasheng-ui/components/ks-month/package.json +3 -0
- package/kuasheng-ui/components/ks-month/range.vue +172 -0
- package/kuasheng-ui/components/ks-month/single.vue +136 -0
- package/kuasheng-ui/components/ks-month/style.less +125 -0
- package/kuasheng-ui/components/ks-month/utils.js +35 -0
- package/kuasheng-ui/components/ks-nav/index.vue +264 -0
- package/kuasheng-ui/components/ks-nav-bar.js +35 -0
- package/kuasheng-ui/components/ks-org/ks-org-tree.vue +247 -0
- package/kuasheng-ui/components/ks-org/ks-popup-tree.vue +154 -0
- package/kuasheng-ui/components/ks-org/ks-tree-input.vue +240 -0
- package/kuasheng-ui/components/ks-org/ks-tree-node.vue +94 -0
- package/kuasheng-ui/components/ks-org/ks-tree.vue +229 -0
- package/kuasheng-ui/components/ks-org/utils.js +54 -0
- package/kuasheng-ui/components/ks-popover/index.vue +457 -0
- package/kuasheng-ui/components/ks-popover/mixin.js +28 -0
- package/kuasheng-ui/components/ks-popover/utils.js +60 -0
- package/kuasheng-ui/components/ks-pull-refresh/index.vue +43 -0
- package/kuasheng-ui/components/ks-quarter/index.vue +256 -0
- package/kuasheng-ui/components/ks-table/README.md +103 -0
- package/kuasheng-ui/components/ks-table/cell.vue +31 -0
- package/kuasheng-ui/components/ks-table/index.js +8 -0
- package/kuasheng-ui/components/ks-table/index.less +486 -0
- package/kuasheng-ui/components/ks-table/index.vue +1088 -0
- package/kuasheng-ui/components/ks-table/package.json +12 -0
- package/kuasheng-ui/components/ks-table/release.md +7 -0
- package/kuasheng-ui/components/ks-toast.js +35 -0
- package/kuasheng-ui/components/ks-upload/index.vue +174 -0
- package/kuasheng-ui/components/ks-user-access.vue +229 -0
- package/kuasheng-ui/components/no-data/README.md +45 -0
- package/kuasheng-ui/components/no-data/image.js +1 -0
- package/kuasheng-ui/components/no-data/index.vue +83 -0
- package/kuasheng-ui/components/notice-bar.vue +16 -0
- package/kuasheng-ui/components/steps.js +11 -0
- package/kuasheng-ui/components/tabs.vue +40 -0
- package/kuasheng-ui/index.js +239 -0
- package/kuasheng-ui/patch/datetime-picker/datetimePicker.md +0 -0
- package/kuasheng-ui/patch/datetime-picker/index.js +46 -0
- package/kuasheng-ui/patch/datetime-picker/utils.js +78 -0
- package/kuasheng-ui/patch/field/field.md +1 -0
- package/kuasheng-ui/patch/field/index.js +122 -0
- package/kuasheng-ui/patch/field/utils.js +36 -0
- package/kuasheng-ui/patch/form/form.md +7 -0
- package/kuasheng-ui/patch/form/index.js +106 -0
- package/kuasheng-ui/patch/index.js +12 -0
- package/kuasheng-ui/patch/pagination/index.js +78 -0
- package/kuasheng-ui/style/animation-ui.less +31 -0
- package/kuasheng-ui/style/font/number/font-number1.otf +0 -0
- package/kuasheng-ui/style/font/number/font-number2.ttf +0 -0
- package/kuasheng-ui/style/images/checked.svg +1 -0
- package/kuasheng-ui/style/images/success.svg +1 -0
- package/kuasheng-ui/style/index.less +6 -0
- package/kuasheng-ui/style/kuasheng-ui.less +207 -0
- package/kuasheng-ui/style/reset-vant.less +307 -0
- package/kuasheng-ui/style/vant-var.less +138 -0
- package/kuasheng-ui/utils/apis.js +17 -0
- package/kuasheng-ui/utils/axios-adapter.js +47 -0
- package/kuasheng-ui/utils/bem.js +39 -0
- package/kuasheng-ui/utils/bus.js +97 -0
- package/kuasheng-ui/utils/common.js +88 -0
- package/kuasheng-ui/utils/decrypt/config.js +12 -0
- package/kuasheng-ui/utils/decrypt/decrypt-api.js +139 -0
- package/kuasheng-ui/utils/decrypt/index.js +6 -0
- package/kuasheng-ui/utils/decrypt/mask.js +36 -0
- package/kuasheng-ui/utils/decrypt/virtual.js +44 -0
- package/kuasheng-ui/utils/directive.js +57 -0
- package/kuasheng-ui/utils/directive.md +23 -0
- package/kuasheng-ui/utils/drcheck-plugin.js +219 -0
- package/kuasheng-ui/utils/error-plugin.js +88 -0
- package/kuasheng-ui/utils/filter.js +149 -0
- package/kuasheng-ui/utils/http-interceptors.js +18 -0
- package/kuasheng-ui/utils/http.js +140 -0
- package/kuasheng-ui/utils/index.js +5 -0
- package/kuasheng-ui/utils/init-event.js +20 -0
- package/kuasheng-ui/utils/log.js +309 -0
- package/kuasheng-ui/utils/token.js +9 -0
- package/kuasheng-ui/utils/type.js +45 -0
- package/kuasheng-ui/utils/validate.js +20 -0
- package/kuasheng-ui/utils/watermark.js +67 -0
- package/kuasheng-ui/version.js +1 -0
- package/ky-apm/client.js +37 -0
- package/ky-apm/customHttp.js +38 -0
- package/ky-apm/index.js +68 -0
- package/ky-apm/plugins/performance.js +84 -0
- package/ky-apm/plugins/self-error.js +26 -0
- package/ky-apm/warn-log.js +3 -0
- package/package.json +81 -10
- package/plugin/ks-chii-webpack-html/index.js +53 -0
- package/plugin/ks-chii-webpack-html/package.json +16 -0
- package/postcss.config.js +15 -0
- package/public/capsule-positon.js +50 -0
- package/public/fonts/DingTalkJinBuTi.ttf +0 -0
- package/public/framework/axios@0.19.0.min.js +9 -0
- package/public/framework/fastclick@1.0.6.min.js +1 -0
- package/public/framework/iconfont/iconfont.css +91 -0
- package/public/framework/iconfont/iconfont.js +1 -0
- package/public/framework/iconfont/iconfont.json +142 -0
- package/public/framework/iconfont/iconfont.ttf +0 -0
- package/public/framework/iconfont/iconfont.woff +0 -0
- package/public/framework/iconfont/iconfont.woff2 +0 -0
- package/public/framework/vant@2.5.6.min.js +7 -0
- package/public/framework/vue-router@3.1.3.min.js +6 -0
- package/public/framework/vue@2.6.10.runtime.min.js +6 -0
- package/public/framework/vuex@3.1.1.min.js +6 -0
- package/public/index.html +260 -0
- package/public/ks@3.0.8.umd.min.js +1 -0
- package/public/ksui@4.0.27.umd.min.js +10 -0
- package/public/status-bar-preset.js +39 -0
- package/{index.js → qt-npm/index.js} +3 -3
- package/qt-npm/package.json +13 -0
- package/src/App.vue +204 -0
- package/src/README.md +15 -0
- package/src/common/README.md +94 -0
- package/src/common/http/axios-adapter.js +47 -0
- package/src/common/http/common.js +88 -0
- package/src/common/http/http-interceptors.js +18 -0
- package/src/common/http/http-lock.js +45 -0
- package/src/common/http/index.js +163 -0
- package/src/common/http/token.js +9 -0
- package/src/common/styles/font/AlibabaSans102Ver2-Md.ttf +0 -0
- package/src/common/styles/font.less +12 -0
- package/src/common/styles/variables.less +43 -0
- package/src/common/utils/index.js +1 -0
- package/src/common/utils/platform/README.md +1 -0
- package/src/common/utils/platform/android/.gitkeep +0 -0
- package/src/common/utils/platform/core/index.js +24 -0
- package/src/common/utils/platform/index.js +164 -0
- package/src/common/utils/platform/ios/.gitkeep +0 -0
- package/src/common/utils/platform/subscribe/helper.js +38 -0
- package/src/common/utils/platform/subscribe/index.js +204 -0
- package/src/common/utils/platform/subscribe/table-animation.js +75 -0
- package/src/config/index.js +31 -0
- package/src/config.js +1 -0
- package/src/main.js +73 -0
- package/src/router.js +52 -0
- package/src/view/home/config.js +101 -0
- package/src/view/home/demo1.vue +223 -0
- package/src/view/home/demo2.vue +124 -0
- package/src/view/home/demo3.vue +51 -0
- package/src/view/home/demo4.vue +140 -0
- package/src/view/home/index.vue +97 -0
- package/src/view/home/query-table/README.md +45 -0
- package/src/view/home/query-table/api/index.js +12 -0
- package/src/view/home/query-table/assets/horizontal-back.svg +1 -0
- package/src/view/home/query-table/components/pe-table/cell.js +181 -0
- package/src/view/home/query-table/components/pe-table/collapse.js +334 -0
- package/src/view/home/query-table/components/pe-table/empty.vue +48 -0
- package/src/view/home/query-table/components/pe-table/header.js +328 -0
- package/src/view/home/query-table/components/pe-table/images/abnormal.png +0 -0
- package/src/view/home/query-table/components/pe-table/images/empty.png +0 -0
- package/src/view/home/query-table/components/pe-table/images/fold.svg +1 -0
- package/src/view/home/query-table/components/pe-table/images/sort.svg +1 -0
- package/src/view/home/query-table/components/pe-table/images/sorting.svg +1 -0
- package/src/view/home/query-table/components/pe-table/images/unfold.svg +1 -0
- package/src/view/home/query-table/components/pe-table/index.vue +847 -0
- package/src/view/home/query-table/components/pe-table/load-more.js +46 -0
- package/src/view/home/query-table/components/pe-table/props/index.js +193 -0
- package/src/view/home/query-table/components/pe-table/row.vue +118 -0
- package/src/view/home/query-table/components/pe-table/scrollbar.js +424 -0
- package/src/view/home/query-table/components/pe-table/stretch-damping.js +112 -0
- package/src/view/home/query-table/components/pe-table/style/cell.less +89 -0
- package/src/view/home/query-table/components/pe-table/style/empty.less +48 -0
- package/src/view/home/query-table/components/pe-table/style/header.less +141 -0
- package/src/view/home/query-table/components/pe-table/style/index.less +88 -0
- package/src/view/home/query-table/components/pe-table/style/load-more.less +61 -0
- package/src/view/home/query-table/components/pe-table/style/row.less +6 -0
- package/src/view/home/query-table/components/pe-table/table-loading.vue +120 -0
- package/src/view/home/query-table/components/pe-table/table-total.vue +57 -0
- package/src/view/home/query-table/components/pe-table/utils/animate.js +80 -0
- package/src/view/home/query-table/components/pe-table/utils/columns.js +290 -0
- package/src/view/home/query-table/components/pe-table/utils/data.js +12 -0
- package/src/view/home/query-table/components/pe-table/utils/fixed.js +69 -0
- package/src/view/home/query-table/components/pe-table/utils/formatter.js +327 -0
- package/src/view/home/query-table/components/pe-table/utils/render-cells.js +424 -0
- package/src/view/home/query-table/components/pe-table/utils/slot.js +28 -0
- package/src/view/home/query-table/components/pe-table/utils/tools.js +84 -0
- package/src/view/home/query-table/components/pe-table/utils/touch-scroll.js +417 -0
- package/src/view/home/query-table/components/query-table/index.vue +497 -0
- package/src/view/home/query-table/components/query-table/mixins/column-mixin.js +102 -0
- package/src/view/home/query-table/components/query-table/mixins/column-setting.js +143 -0
- package/src/view/home/query-table/components/query-table/mixins/data-mixin.js +519 -0
- package/src/view/home/query-table/components/query-table/mixins/pagination-mixin.js +26 -0
- package/src/view/home/query-table/components/query-table/mixins/table-fixed.js +130 -0
- package/src/view/home/query-table/components/query-table/mixins/table-horizontal.js +119 -0
- package/src/view/home/query-table/components/table-horizontal.vue +99 -0
- package/src/view/home/query-table/components/table-pagination.vue +32 -0
- package/src/view/home/query-table/components/table-settings/assets/arrpw-up.svg +1 -0
- package/src/view/home/query-table/components/table-settings/assets/disabled-down.svg +1 -0
- package/src/view/home/query-table/components/table-settings/assets/disabled-up.svg +1 -0
- package/src/view/home/query-table/components/table-settings/assets/down.svg +1 -0
- package/src/view/home/query-table/components/table-settings/assets/up.svg +1 -0
- package/src/view/home/query-table/components/table-settings/index.less +294 -0
- package/src/view/home/query-table/components/table-settings/index.vue +260 -0
- package/src/view/home/query-table/components/table-settings/settings.vue +479 -0
- package/src/view/home/query-table/components/table-settings/test.js +626 -0
- package/src/view/home/query-table/components/table-settings//344/270/252/346/200/247/350/256/276/347/275/256.md +0 -0
- package/src/view/home/query-table/components/tooltip.js +124 -0
- package/src/view/home/query-table/hooks/use-cache-promise.js +27 -0
- package/src/view/home/query-table/hooks/use-column-config.js +190 -0
- package/src/view/home/query-table/hooks/use-encryption.js +0 -0
- package/src/view/home/query-table/hooks/use-generic-search.js +95 -0
- package/src/view/home/query-table/index.js +7 -0
- package/src/view/home/query-table/store/column-store.js +0 -0
- package/src/view/home/query-table/styles/table.less +24 -0
- package/src/view/home/query-table/utils/column.js +36 -0
- package/src/view/home/query-table/utils/config.js +12 -0
- package/src/view/home/query-table/utils/encryption.js +32 -0
- package/src/view/home/query-table/utils/http.js +1 -0
- package/src/view/home/query-table/utils/localStorage.js +35 -0
- package/src/view/home//351/246/226/351/241/265.md +0 -0
- package/src/web.js +99 -0
- package/vue.config.js +131 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {http} from './http'
|
|
2
|
+
// 检查request有没有加载
|
|
3
|
+
export function initEvent() {
|
|
4
|
+
if (window.ks && window.ks.request) {
|
|
5
|
+
dispatchEvent()
|
|
6
|
+
} else {
|
|
7
|
+
setTimeout(() => {
|
|
8
|
+
if (window.ks && window.ks.request) {
|
|
9
|
+
_dispatchEvent()
|
|
10
|
+
} else {
|
|
11
|
+
initEvent()
|
|
12
|
+
}
|
|
13
|
+
}, 300)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function _dispatchEvent() {
|
|
17
|
+
window.dispatchEvent(new CustomEvent('__ks_ready__', {
|
|
18
|
+
detail: {http}
|
|
19
|
+
}))
|
|
20
|
+
}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import bus from './bus'
|
|
2
|
+
import { getToken } from './token'
|
|
3
|
+
import { md5Http, getKsEnv } from './common'
|
|
4
|
+
// import {http} from './http'
|
|
5
|
+
|
|
6
|
+
const axios = window.axios
|
|
7
|
+
const API_CODE = 'cts.trace.uploadWebActionLog'
|
|
8
|
+
|
|
9
|
+
const collectApiMap = {
|
|
10
|
+
uat: 'https://collect-uat.ky-express.com/json/collector',
|
|
11
|
+
prd: 'https://collect.ky-express.com/json/collector'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
class LogPlugin {
|
|
15
|
+
constructor (option = {}) {
|
|
16
|
+
this.userId = option.userId
|
|
17
|
+
this.menuId = option.menuId
|
|
18
|
+
this.countThreshold = option.countThreshold || 10
|
|
19
|
+
this.timeThreshold = option.timeThreshold || 10 //秒
|
|
20
|
+
this.sizeThreshold = option.sizeThreshold || 10 //kb
|
|
21
|
+
this.deounceThreshold = option.deounceThreshold || 300 //毫秒
|
|
22
|
+
this.uploadDebouncTime = null
|
|
23
|
+
this.initTime = Date.now()
|
|
24
|
+
this.reportList = []
|
|
25
|
+
this.lastActionName = ''
|
|
26
|
+
this.lastActionId = ''
|
|
27
|
+
this.immediateReport = false
|
|
28
|
+
this.ignoreUrl = [API_CODE].concat(option.ignoreUrl || [])
|
|
29
|
+
this.ignoreClass = ['log-disabled','el-dialog__wrapper','main-panel'].concat(option.ignoreClass || [])
|
|
30
|
+
this.ignoreTag = ['canvas'].concat(option.ignoreTag || [])
|
|
31
|
+
this.init()
|
|
32
|
+
// this.firstReport()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
init () {
|
|
36
|
+
this.ignoreUrl.push('mcs.user.menu.access.report')
|
|
37
|
+
window.setInterval(this.checkReport.bind(this), this.timeThreshold * 1000)
|
|
38
|
+
this.addEventListener()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
setOption(option) {
|
|
42
|
+
Object.keys(option).forEach(item => {
|
|
43
|
+
if (this.hasOwnProperty(item)) {
|
|
44
|
+
this[item] = option[item]
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
console.log(this)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async reportOnInit() {
|
|
51
|
+
let menu = window.ksui && window.ksui.menu
|
|
52
|
+
let info = await window.ks.getUserInfo()
|
|
53
|
+
let user = info.userInfo || {}
|
|
54
|
+
let userId = this.userId || user.id
|
|
55
|
+
if (!userId || !menu.id) {
|
|
56
|
+
console.warn(`[log-plugin 首次上报] userId或menuId未获取到`)
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
let report = this.getNormalizerReport()
|
|
60
|
+
report.menuId = menu.id
|
|
61
|
+
report.userId = userId
|
|
62
|
+
report.location = 'h5'
|
|
63
|
+
report.navigator = navigator.appVersion || navigator.userAgent
|
|
64
|
+
report.navigator = report.navigator + ' KSUI:' + window.ksui.version
|
|
65
|
+
report.xpath = this.makeActionId()
|
|
66
|
+
report.action = '首次进入'
|
|
67
|
+
report.startTime = String(this.initTime)
|
|
68
|
+
report.endTime = '0'
|
|
69
|
+
report.url = 'h5'
|
|
70
|
+
report.httpStatus = '200'
|
|
71
|
+
// `${user.id}-${now}-${random(4)}-${menu.id || 'xxxx'}`
|
|
72
|
+
report.webTraceId = `${userId}-${menu && menu.id || 'xxxx'}-${String(this.initTime)}-${this.lastActionId || this.randomCode()}-${Math.floor(1000 + 1000 * Math.random())}`
|
|
73
|
+
// report.webTraceId = userId + '-' + Date.now() + '-' + Math.floor(1000 + 1000 * Math.random()) + '-' + menu.id
|
|
74
|
+
report.requestHeaders = `${userId}-${String(menu.id)}-${String(this.initTime)}`
|
|
75
|
+
report.resCode = 0
|
|
76
|
+
console.log('首次上报', report)
|
|
77
|
+
report.immediate = true
|
|
78
|
+
this.reportList.push(report)
|
|
79
|
+
this.checkReport()
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
firstReport() {
|
|
83
|
+
if (window.ks && window.ks.request) {
|
|
84
|
+
this.reportOnInit()
|
|
85
|
+
} else {
|
|
86
|
+
setTimeout(() => {
|
|
87
|
+
if (window.ks && window.ks.request) {
|
|
88
|
+
this.reportOnInit()
|
|
89
|
+
} else {
|
|
90
|
+
this.firstReport()
|
|
91
|
+
}
|
|
92
|
+
}, 10)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
getNormalizerReport () {
|
|
97
|
+
return {
|
|
98
|
+
xpath: '', // 事件id
|
|
99
|
+
action: '', // 事件名称
|
|
100
|
+
userId: this.userId || window.ksui && window.ksui.user && window.ksui.user.id,
|
|
101
|
+
menuId: '',
|
|
102
|
+
startTime: '',
|
|
103
|
+
endTime: '',
|
|
104
|
+
url: '',
|
|
105
|
+
requestHeaders: '', // 模块首次进入时间
|
|
106
|
+
requestBody: '', // 弃用
|
|
107
|
+
responseHeaders: '', // 弃用
|
|
108
|
+
responseData: '', // 弃用
|
|
109
|
+
httpStatus: '',
|
|
110
|
+
webTraceId: '',
|
|
111
|
+
resCode: '',
|
|
112
|
+
immediate: this.immediateReport
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
checkReport () {
|
|
117
|
+
|
|
118
|
+
if (this.reportList.some(item => item.immediate)) {
|
|
119
|
+
console.log(`[log-plugin] 触发立即上报`)
|
|
120
|
+
this.upload()
|
|
121
|
+
this.clear()
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
if (this.uploadDebouncTime) {
|
|
125
|
+
clearTimeout(this.uploadDebouncTime)
|
|
126
|
+
}
|
|
127
|
+
if (this.reportList.length >= this.countThreshold) {
|
|
128
|
+
console.log(`[log-plugin] 达到采集条数: ${this.countThreshold}上报`)
|
|
129
|
+
this.upload()
|
|
130
|
+
this.clear()
|
|
131
|
+
} else {
|
|
132
|
+
this.uploadDebouncTime = setTimeout(() => {
|
|
133
|
+
this.upload()
|
|
134
|
+
this.clear()
|
|
135
|
+
}, this.deounceThreshold)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
clear () {
|
|
140
|
+
this.reportList = []
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
upload () {
|
|
144
|
+
if (!this.reportList.length) return
|
|
145
|
+
const data = this.reportList
|
|
146
|
+
const token = getToken()
|
|
147
|
+
const menu = window.ksui.menu
|
|
148
|
+
const env = getKsEnv()
|
|
149
|
+
const now = Date.now()
|
|
150
|
+
const headers = {
|
|
151
|
+
// timestamp: Date.now(),
|
|
152
|
+
// $config: {
|
|
153
|
+
// _tips: false
|
|
154
|
+
// }
|
|
155
|
+
format: 'JSON',
|
|
156
|
+
method: API_CODE,
|
|
157
|
+
appkey: '50159',
|
|
158
|
+
token: getToken(),
|
|
159
|
+
timestamp: now,
|
|
160
|
+
'X-Env': env || 'uat',
|
|
161
|
+
'X-menu-id': menu.id,
|
|
162
|
+
sign: md5Http(token, now, data)
|
|
163
|
+
}
|
|
164
|
+
const BaseUrl = collectApiMap[env] || collectApiMap['uat']
|
|
165
|
+
axios({
|
|
166
|
+
method: 'post',
|
|
167
|
+
url: `${BaseUrl}?${API_CODE}`,
|
|
168
|
+
data,
|
|
169
|
+
headers
|
|
170
|
+
}).then(() => {
|
|
171
|
+
console.log(`[log-plugin] 日志上报成功`)
|
|
172
|
+
}).catch(error => {
|
|
173
|
+
console.log(error)
|
|
174
|
+
console.log(`[log-plugin] 日志上报失败`)
|
|
175
|
+
})
|
|
176
|
+
// http(API_CODE, 50159, data, {headers}).then(() => {
|
|
177
|
+
// console.log(`[log-plugin] 日志上报成功`)
|
|
178
|
+
// }).catch(error => {
|
|
179
|
+
// console.log(error)
|
|
180
|
+
// console.log(`[log-plugin] 日志上报失败`)
|
|
181
|
+
// })
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
makeReport(axiosResponse) {
|
|
185
|
+
let ua = navigator.appVersion || navigator.userAgent
|
|
186
|
+
let config = axiosResponse.config
|
|
187
|
+
let menuId = this.menuId || config.headers['X-menu-id']
|
|
188
|
+
let report = this.getNormalizerReport()
|
|
189
|
+
if (!report.userId) {
|
|
190
|
+
console.warn(`[log-plugin] userId未获取到,请设置userId: ksui.log.userId = "用户id"`)
|
|
191
|
+
return false
|
|
192
|
+
}
|
|
193
|
+
if (!menuId) {
|
|
194
|
+
console.warn(`[log-plugin] menuId未获取到,请设置menuId: ksui.log.menuId = "菜单id"`)
|
|
195
|
+
return false
|
|
196
|
+
}
|
|
197
|
+
if (!/^[0-9]+$/.test(menuId)) {
|
|
198
|
+
console.warn(`[log-plugin] menuId格式错误: ${menuId}, 应该是全数字`)
|
|
199
|
+
return false
|
|
200
|
+
}
|
|
201
|
+
report.menuId = String(menuId)
|
|
202
|
+
report.location = config.location || ''
|
|
203
|
+
report.navigator = ua
|
|
204
|
+
report.xpath = config.lastActionId || ''
|
|
205
|
+
report.action = config.lastActionName || ''
|
|
206
|
+
report.startTime = String(config.startTime || 0)
|
|
207
|
+
report.endTime = String(Date.now())
|
|
208
|
+
report.url = config.url || ''
|
|
209
|
+
report.httpStatus = String(axiosResponse.status || '')
|
|
210
|
+
report.webTraceId = config.headers['x-webtrace-id']
|
|
211
|
+
report.requestHeaders = `${report.userId}-${String(menuId)}-${String(this.initTime)}`
|
|
212
|
+
if (axiosResponse.data && axiosResponse.data.code !== undefined) {
|
|
213
|
+
report.resCode = String(axiosResponse.data.code)
|
|
214
|
+
}
|
|
215
|
+
return report
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
collectRequest (config) {
|
|
219
|
+
config.startTime = config.headers.timestamp || Date.now()
|
|
220
|
+
config.lastActionName = this.lastActionName
|
|
221
|
+
config.lastActionId = this.lastActionId
|
|
222
|
+
config.location = location.host
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
collectResponse (axiosResponse) {
|
|
226
|
+
let conf = axiosResponse.config
|
|
227
|
+
// 过滤掉不走开放平台的接口,第三方接口不采集
|
|
228
|
+
if (!conf.headers || !conf.headers.method) {
|
|
229
|
+
return
|
|
230
|
+
}
|
|
231
|
+
// 过滤掉标注为不上报日志的接口
|
|
232
|
+
if (conf.$config && conf.$config._log === false) {
|
|
233
|
+
return
|
|
234
|
+
}
|
|
235
|
+
// 过滤不上报的method
|
|
236
|
+
if (this.ignoreUrl.some(url => conf.headers.method.indexOf(url) >= 0) || this.ignoreUrl.some(url => conf.url.indexOf(url) >= 0)) {
|
|
237
|
+
return
|
|
238
|
+
}
|
|
239
|
+
if (conf.lastActionName && conf.lastActionId ) {
|
|
240
|
+
let report = this.makeReport(axiosResponse)
|
|
241
|
+
if (report) {
|
|
242
|
+
this.immediateReport = false
|
|
243
|
+
this.reportList.push(report)
|
|
244
|
+
this.checkReport()
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
randomCode () {
|
|
250
|
+
let id = this.userId || window.ksui && window.ksui.user && window.ksui.user.id || ''
|
|
251
|
+
return '' + id + Date.now() + Math.floor(1000 + 1000 * Math.random())
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
isIgnore (dom) {
|
|
255
|
+
if (!dom) return true
|
|
256
|
+
let classList = dom.className
|
|
257
|
+
let tagName = dom.tagName && dom.tagName.toLocaleLowerCase()
|
|
258
|
+
let ignore = this.ignoreClass.some(c => typeof classList === 'string' && classList.indexOf(c) >= 0) || this.ignoreTag.some(t => tagName.indexOf(t) >= 0)
|
|
259
|
+
return ignore
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
handleEvent (e) {
|
|
263
|
+
if (this.isIgnore(e.target)) {
|
|
264
|
+
this.lastActionName = ''
|
|
265
|
+
this.lastActionId = ''
|
|
266
|
+
} else {
|
|
267
|
+
let text = e.target.textContent || ''
|
|
268
|
+
this.lastActionName = text ? text.trim().replace(/\s/g, '').substr(0, 10) : text
|
|
269
|
+
this.lastActionId = this.randomCode()
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// 自定义日志事件名称
|
|
274
|
+
click (option = {}) {
|
|
275
|
+
if (typeof option === 'string') {
|
|
276
|
+
this.lastActionName = option
|
|
277
|
+
return
|
|
278
|
+
}
|
|
279
|
+
if (option.actionName) {
|
|
280
|
+
this.lastActionName = option.actionName
|
|
281
|
+
}
|
|
282
|
+
if (option.actionId) {
|
|
283
|
+
this.lastActionId = option.actionId
|
|
284
|
+
}
|
|
285
|
+
if (option.immediate) {
|
|
286
|
+
this.immediateReport = option.immediate
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
addEventListener () {
|
|
291
|
+
document.addEventListener('click', this.handleEvent.bind(this), true)
|
|
292
|
+
bus.$on('httpStart', this.collectRequest.bind(this))
|
|
293
|
+
bus.$on('httpEnd', this.collectResponse.bind(this))
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
makeActionId() {
|
|
297
|
+
return this.randomCode()
|
|
298
|
+
}
|
|
299
|
+
// httpStart(request) {
|
|
300
|
+
// this.collectRequest(request)
|
|
301
|
+
// }
|
|
302
|
+
|
|
303
|
+
// httpEnd(response) {
|
|
304
|
+
// this.collectResponse(response)
|
|
305
|
+
// }
|
|
306
|
+
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export default new LogPlugin()
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export const toString = Object.prototype.toString;
|
|
2
|
+
|
|
3
|
+
export const is = (type, primitive = false) => {
|
|
4
|
+
return function (obj) {
|
|
5
|
+
return primitive
|
|
6
|
+
? typeof obj === type.toLowerCase()
|
|
7
|
+
: toString.call(obj) === `[object ${type}]`;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @method 检测当前类型是否为函数
|
|
13
|
+
* @param item 检测当前类型
|
|
14
|
+
* @returns { Boolean } 如果是函数则返回true、否则返回false
|
|
15
|
+
*/
|
|
16
|
+
export function isFunction(item) {
|
|
17
|
+
return is('Function')(item);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @method 检测当前类型是否为字符串
|
|
22
|
+
* @param item 检测当前类型
|
|
23
|
+
* @returns { Boolean } 如果是字符串则返回true、否则返回false
|
|
24
|
+
*/
|
|
25
|
+
export function isString(item) {
|
|
26
|
+
return is('String', true)(item);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @method 检测当前类型是否为数字
|
|
31
|
+
* @param item 检测当前类型
|
|
32
|
+
* @returns { Boolean } 如果是数字则返回true、否则返回false
|
|
33
|
+
*/
|
|
34
|
+
export function isNumber(item) {
|
|
35
|
+
return is('Number', true)(item);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @method 检测当前类型是否为布尔
|
|
40
|
+
* @param item 检测当前类型
|
|
41
|
+
* @returns { Boolean } 如果是布尔则返回true、否则返回false
|
|
42
|
+
*/
|
|
43
|
+
export function isBoolean(item) {
|
|
44
|
+
return is('Boolean', true)(item);
|
|
45
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const valid = (data, schema) => {
|
|
2
|
+
Object.keys(schema).forEach(key => {
|
|
3
|
+
validate(data[key], schema[key])
|
|
4
|
+
})
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const validate = (value, rules) => {
|
|
8
|
+
rules.forEach(rule => {
|
|
9
|
+
Object.keys(rule).forEach(item => {
|
|
10
|
+
[item](value, rule[item])
|
|
11
|
+
})
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const type = (value, type) => {
|
|
16
|
+
if (typeof value === type) {
|
|
17
|
+
return true
|
|
18
|
+
}
|
|
19
|
+
return false
|
|
20
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// 添加自定义水印
|
|
2
|
+
export const customWatermark = (text = '', el = '.ksui-container, .van-dialog, .ksui-card, .ks-table', color = 'rgba(0,0,0,0.1)', rotate = 30) => {
|
|
3
|
+
let canvas = document.createElement('canvas')
|
|
4
|
+
let ctx = canvas.getContext('2d')
|
|
5
|
+
ctx.font = '100 12px PingFangSC'
|
|
6
|
+
// 角度转弧度
|
|
7
|
+
rotate = (rotate * Math.PI) / 180
|
|
8
|
+
let text1 = ''
|
|
9
|
+
let text2 = ''
|
|
10
|
+
// text参数是数组则文本分两行
|
|
11
|
+
if (Array.isArray(text)) {
|
|
12
|
+
text1 = text[0]
|
|
13
|
+
text2 = text[1]
|
|
14
|
+
} else {
|
|
15
|
+
text1 = text
|
|
16
|
+
}
|
|
17
|
+
let text1Width = ctx.measureText(text1).width
|
|
18
|
+
let text2Width = ctx.measureText(text2).width
|
|
19
|
+
let l = text1Width > text2Width ? text1Width : text2Width
|
|
20
|
+
// 将文本长度作为斜边求两个直角边
|
|
21
|
+
let top = Math.floor(l * Math.sin(rotate))
|
|
22
|
+
let left = Math.floor(l * Math.cos(rotate))
|
|
23
|
+
|
|
24
|
+
let dpr = window.devicePixelRatio
|
|
25
|
+
const cssWidth = left + 50
|
|
26
|
+
const cssHeight = top + 80
|
|
27
|
+
|
|
28
|
+
// canvas.style.width = cssWidth + 'px'
|
|
29
|
+
// canvas.style.height = cssHeight + 'px'
|
|
30
|
+
|
|
31
|
+
canvas.width = cssWidth * dpr
|
|
32
|
+
canvas.height = cssHeight * dpr
|
|
33
|
+
|
|
34
|
+
ctx.scale(dpr, dpr)
|
|
35
|
+
ctx.fillStyle = color
|
|
36
|
+
ctx.textBaseline = 'middle'
|
|
37
|
+
ctx.rotate(-rotate)
|
|
38
|
+
ctx.fillText(text1, 0, top)
|
|
39
|
+
ctx.fillText(text2, 0, top + 10)
|
|
40
|
+
|
|
41
|
+
let encode = canvas.toDataURL('image/png')
|
|
42
|
+
let style = document.createElement('style')
|
|
43
|
+
style.type = 'text/css'
|
|
44
|
+
style.innerHTML = `${el}{background-image:url(${encode});background-size: ${cssWidth}px ${cssHeight}px;}`
|
|
45
|
+
document.querySelector('head').appendChild(style)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 添加水印方法,调用ksui.watermark
|
|
50
|
+
* @param {string} employeeNumber 工号
|
|
51
|
+
* @param {sting} el css选择器
|
|
52
|
+
* @param {string} color 水印文字颜色(格式rgba)
|
|
53
|
+
*/
|
|
54
|
+
const watermark = (employeeNumber = '', el = '.ksui-container, .van-dialog, .ksui-card, .ks-table', color = '#F0F3F9') => {
|
|
55
|
+
let date = new Date()
|
|
56
|
+
const f = num => {
|
|
57
|
+
let str = String(num)
|
|
58
|
+
return str.length === 1 ? '0' + str : str
|
|
59
|
+
}
|
|
60
|
+
let text = [
|
|
61
|
+
`${employeeNumber}`,
|
|
62
|
+
`${date.getFullYear()}/${f(date.getMonth() + 1)}/${f(date.getDate())} ${f(date.getHours())}:${f(date.getMinutes())}:${f(date.getSeconds())}`
|
|
63
|
+
]
|
|
64
|
+
customWatermark(text, el, color)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export default watermark
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default '3.0.43'
|
package/ky-apm/client.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ky-apm 采集上报模块
|
|
3
|
+
* 白名单 white-list
|
|
4
|
+
* http
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
import {warnLog} from './warn-log';
|
|
8
|
+
|
|
9
|
+
class Client {
|
|
10
|
+
constructor(appConfig) {
|
|
11
|
+
this.appConfig = appConfig;
|
|
12
|
+
}
|
|
13
|
+
getConfig() {
|
|
14
|
+
return this.appConfig
|
|
15
|
+
}
|
|
16
|
+
// 上报模块
|
|
17
|
+
reportData (data) {
|
|
18
|
+
// 判断类型(轻应用、erp、自定义上传)
|
|
19
|
+
try {
|
|
20
|
+
if (this.appConfig.customReport && typeof this.appConfig.customReport === 'function') {
|
|
21
|
+
this.appConfig.customReport(data)
|
|
22
|
+
} else if (this.appConfig.app === 'apm-ks') {
|
|
23
|
+
// 轻应用
|
|
24
|
+
window.ksui && window.ksui.http(this.appConfig.reportUrl, this.appConfig.appkey, data)
|
|
25
|
+
} else if (this.appConfig.app === 'apm-erp') {
|
|
26
|
+
// 铸剑(需要将铸剑的http实例传入)
|
|
27
|
+
if (this.appConfig.$http && typeof this.appConfig.$http === 'function') {
|
|
28
|
+
this.appConfig.$http(this.appConfig.reportUrl, data, { log: false, cancel: true, appkey: this.appConfig.appkey })
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
console.log('[kyApm上报成功]')
|
|
32
|
+
} catch (error) {
|
|
33
|
+
warnLog(error)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export default Client
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// 该 js 是提供给客户端帮忙注入到轻应用,hook了请求,自定义上报请求到 apm 平台(走原生请求采集不到请求日志)
|
|
2
|
+
if (window.ks && window.ks.request && !window.__APMCUSTOMHTTP) {
|
|
3
|
+
window.ks.request = function (method, body = {}, headers = {}) {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
window.ks.callFunc({
|
|
6
|
+
method: 'request',
|
|
7
|
+
params: {
|
|
8
|
+
method,
|
|
9
|
+
body,
|
|
10
|
+
headers
|
|
11
|
+
}
|
|
12
|
+
}).then(resp => {
|
|
13
|
+
resolve(resp)
|
|
14
|
+
try {
|
|
15
|
+
if (window._apm ) {
|
|
16
|
+
let now = Date.now()
|
|
17
|
+
const rt = now - headers.timestamp
|
|
18
|
+
window._apm('sendAPILog', {
|
|
19
|
+
url: method || '', // 请求地址
|
|
20
|
+
method: 2, // 请求类型:2=POST
|
|
21
|
+
rc: 200, // 请求状态
|
|
22
|
+
rt: rt,
|
|
23
|
+
traceid: headers.webTraceId || '',
|
|
24
|
+
req_body: '',
|
|
25
|
+
req_query: ''
|
|
26
|
+
})
|
|
27
|
+
window.__APMCUSTOMHTTP = true
|
|
28
|
+
console.log('上报apm自定义')
|
|
29
|
+
}
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.error('【apm自定义上报http错误】:', error)
|
|
32
|
+
}
|
|
33
|
+
}).catch(err => {
|
|
34
|
+
reject(err)
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
}
|
package/ky-apm/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ky-apm 采集上报模块
|
|
3
|
+
* 白名单 white-list
|
|
4
|
+
* http
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
import {warnLog} from './warn-log';
|
|
8
|
+
import Client from './client'
|
|
9
|
+
import SelfError from './plugins/self-error.js'
|
|
10
|
+
import PerformancePlugin from './plugins/performance.js'
|
|
11
|
+
var plugins = [PerformancePlugin]
|
|
12
|
+
var defaultConfig = {
|
|
13
|
+
reportUrl: 'fmk.monitor.frontexception.log.report',
|
|
14
|
+
appkey: '55212',
|
|
15
|
+
performance: { // 性能相关参数
|
|
16
|
+
durationTime: 2000, // 性能采集的统计时长阀值
|
|
17
|
+
},
|
|
18
|
+
navigator: navigator && navigator.userAgent || '',
|
|
19
|
+
app: 'apm-ks', // apm-ks, apm-erp
|
|
20
|
+
module: '', // 当前模块名称
|
|
21
|
+
userName: '', // 当前用户姓名
|
|
22
|
+
userId: '', // 当前用户userId
|
|
23
|
+
logType: 'performance', // 性能采集: performance
|
|
24
|
+
logId: 'kyApm',
|
|
25
|
+
whiteList: [] // 需要监控的白名单userId列表
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var kyApm = {
|
|
29
|
+
init (config = {}) {
|
|
30
|
+
try {
|
|
31
|
+
if (this.isInit) {
|
|
32
|
+
warnLog('KyApm已经初始化,请勿重复初始化!')
|
|
33
|
+
return false
|
|
34
|
+
}
|
|
35
|
+
if (config.whiteList && config.whiteList.length && !config.whiteList.includes(config.userId)) {
|
|
36
|
+
warnLog('该用户不在收集白名单中,KyApm不采集数据!')
|
|
37
|
+
return false
|
|
38
|
+
}
|
|
39
|
+
this.isInit = false
|
|
40
|
+
this.config = { ...defaultConfig, ...config }
|
|
41
|
+
this.client = new Client(this.config)
|
|
42
|
+
this.selfError = new SelfError(this.client, this.config)
|
|
43
|
+
this.initPlugins(this.client, this.selfError)
|
|
44
|
+
this.isInit = true
|
|
45
|
+
console.log('KyApm初始化成功')
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.log('----', this.selfError)
|
|
48
|
+
warnLog(error)
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
initPlugins (client, selfError) {
|
|
52
|
+
try {
|
|
53
|
+
plugins.forEach(plugin => {
|
|
54
|
+
new plugin(client, selfError)
|
|
55
|
+
})
|
|
56
|
+
} catch (error) {
|
|
57
|
+
this.selfError.error(error)
|
|
58
|
+
warnLog(error)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 浏览器环境直接挂载插件
|
|
64
|
+
if (typeof window !== 'undefined' && !window.kyApm) {
|
|
65
|
+
window.kyApm = kyApm
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default kyApm
|