js.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. <template>
  2. <!-- 对应页面: js报错 -->
  3. <view class="fix-top-window">
  4. <view class="uni-header">
  5. <uni-stat-breadcrumb class="uni-stat-breadcrumb-on-phone" />
  6. <view class="uni-group hide-on-phone">
  7. <!-- <view class="uni-title">错误分析</view> -->
  8. <view class="uni-sub-title">开发者可以在这里快速查询应用最近出现的具体错误内容,了解错误概况信息,以便快速修复问题</view>
  9. </view>
  10. </view>
  11. <view class="uni-container">
  12. <view class="uni-stat--x flex">
  13. <uni-data-select collection="opendb-app-list" field="appid as value, name as text" orderby="text asc"
  14. :defItem="1" label="应用选择" v-model="query.appid" :clear="false" />
  15. <uni-data-select collection="opendb-app-versions" :where="versionQuery"
  16. field="_id as value, version as text" orderby="text desc" label="版本选择" v-model="query.version_id" />
  17. <view class="flex">
  18. <uni-stat-tabs label="日期选择" :current="currentDateTab" :yesterday="false" mode="date"
  19. @change="changeTimeRange" />
  20. <uni-datetime-picker type="daterange" :end="new Date().getTime()" v-model="query.start_time"
  21. returnType="timestamp" :clearIcon="false" class="uni-stat-datetime-picker"
  22. :class="{'uni-stat__actived': currentDateTab < 0 && !!query.start_time.length}"
  23. @change="useDatetimePicker" />
  24. </view>
  25. </view>
  26. <view class="uni-stat--x">
  27. <uni-stat-tabs label="平台选择" type="boldLine" mode="platform" v-model="query.platform_id"
  28. @change="changePlatform" />
  29. </view>
  30. <view class="uni-stat--x" style="padding: 15px 0;">
  31. <uni-stat-panel :items="panelData" class="uni-stat-panel" />
  32. <uni-stat-tabs type="box" v-model="chartTab" :tabs="chartTabs" class="mb-l" />
  33. <view class="uni-charts-box">
  34. <qiun-data-charts type="area" :chartData="chartData" :eopts="{notMerge:true}" echartsH5 echartsApp
  35. tooltipFormat="tooltipCustom" />
  36. </view>
  37. </view>
  38. <view class="uni-stat--x p-m">
  39. <view class="flex-between">
  40. <view class="uni-stat-card-header">信息列表</view>
  41. <view class="uni-group">
  42. <!-- #ifdef H5 -->
  43. <button v-if="sourceMapEnabled" class="uni-button" type="primary" size="mini"
  44. @click="openUploadPopup">上传
  45. sourceMap</button>
  46. <!-- #endif -->
  47. </view>
  48. </view>
  49. <uni-table :loading="loading" border stripe :emptyText="$t('common.empty')">
  50. <uni-tr>
  51. <template v-for="(mapper, index) in fieldsMap">
  52. <uni-th v-if="mapper.title" :key="index" align="center">
  53. <!-- #ifdef MP -->
  54. {{mapper.title}}
  55. <!-- #endif -->
  56. <!-- #ifndef MP -->
  57. <uni-tooltip>
  58. {{mapper.title}}
  59. <uni-icons v-if="mapper.tooltip" type="help" color="#666" />
  60. <template v-if="mapper.tooltip" v-slot:content>
  61. <view class="uni-stat-tooltip-s">
  62. {{mapper.tooltip}}
  63. </view>
  64. </template>
  65. </uni-tooltip>
  66. <!-- #endif -->
  67. </uni-th>
  68. </template>
  69. <uni-th align="center" v-if="sourceMapEnabled">
  70. 操作
  71. </uni-th>
  72. </uni-tr>
  73. <uni-tr v-for="(item ,i) in tableData" :key="i">
  74. <template v-for="(mapper, index) in fieldsMap">
  75. <uni-td v-if="mapper.field === 'count'" :key="mapper.field" align="center">
  76. <text class="link-btn" @click="navTo('detail', item)">
  77. {{item[mapper.field] !== undefined ? item[mapper.field] : '-'}}
  78. </text>
  79. </uni-td>
  80. <uni-td v-else :key="mapper.field" align="center">
  81. {{item[mapper.field] !== undefined ? item[mapper.field] : '-'}}
  82. </uni-td>
  83. </template>
  84. <uni-td v-if="sourceMapEnabled">
  85. <button size="mini" type="primary" style="white-space: nowrap;"
  86. @click="openErrPopup(item)">详 情</button>
  87. </uni-td>
  88. </uni-tr>
  89. </uni-table>
  90. <view class="uni-pagination-box">
  91. <uni-pagination show-icon show-page-size :page-size="options.pageSize"
  92. :current="options.pageCurrent" :total="options.total" @change="changePageCurrent"
  93. @pageSizeChange="changePageSize" />
  94. </view>
  95. </view>
  96. </view>
  97. <uni-popup ref="errMsg" type="center" :animation="false" :maskClick="true" @change="errMsgPopupChange">
  98. <view class="modal black-theme">
  99. <view class="modal-header">
  100. 错误详情
  101. </view>
  102. <scroll-view scroll-x="true" scroll-y="true">
  103. <view class="modal-content" style="padding: 20px 30px;">
  104. <view v-if="msgLoading" style="margin: 150px 0;text-align: center;font-size: 14px;">
  105. <uni-load-more class="mb-m" :showText="false" status="loading" />
  106. <view>正在解析,请稍等...</view>
  107. </view>
  108. <!-- <pre>{{errMsg}}</pre> -->
  109. <text>{{errMsg}}</text>
  110. </view>
  111. </scroll-view>
  112. <view class="dialog-close" @click="closeErrPopup">
  113. <view class="dialog-close-plus" data-id="close"></view>
  114. <view class="dialog-close-plus dialog-close-rotate" data-id="close"></view>
  115. </view>
  116. </view>
  117. </uni-popup>
  118. <!-- #ifdef H5 -->
  119. <uni-drawer class="sourcemap-drawser" ref="upload" mode="right" :mask-click="true" :width="340">
  120. <view class="modal" style="max-width: none; min-width: auto;">
  121. <view class="modal-header">
  122. 上传 sourceMap
  123. </view>
  124. <view class="modal-content" style="height: 300px;padding: 0;">
  125. <uni-data-select collection="opendb-app-list" field="appid as value, name as text"
  126. orderby="text asc" label="应用" v-model="uploadOptions.appid" />
  127. <uni-data-select collection="uni-stat-app-platforms" field="code as value, name as text"
  128. orderby="text asc" label="平台" v-model="uploadOptions.uni_platform" />
  129. <uni-data-select collection="opendb-app-versions" :where="uploadVersionQuery"
  130. field="version as value, version as text" orderby="text desc" label="版本"
  131. v-model="uploadOptions.version" />
  132. <view class="flex m-m">
  133. <view class="label-text">选择文件:</view>
  134. <button class="uni-button ml-m" type="primary" @click="choosefile">选择文件并上传</button>
  135. </view>
  136. <view v-if="!vaildate" class="upload-msg-warning">
  137. {{uploadMsg}}
  138. </view>
  139. </view>
  140. <view class="dialog-close" @click="closeUploadPopup">
  141. <view class="dialog-close-plus" style="background-color: #333;" data-id="close"></view>
  142. <view class="dialog-close-plus dialog-close-rotate" style="background-color: #333;" data-id="close">
  143. </view>
  144. </view>
  145. </view>
  146. <view class="upload-task-header">
  147. <text>上传任务:{{uploadSuccessTasks.length}}/{{uploadFile.tempFileTasks.length}}</text>
  148. </view>
  149. <scroll-view v-if="uploadFile.tempFileTasks.length" style="height: calc(100vh - 362px);" scroll-y="true">
  150. <view v-if="uploadFile.tempFileTasks.length > uploadSuccessTasks.length">
  151. <view class="upload-task-header">
  152. <text>正在上传</text>
  153. </view>
  154. <uploadTask :uploadTasks="sortUploadFileTempFileTasks"></uploadTask>
  155. </view>
  156. <view v-if="uploadSuccessTasks.length">
  157. <view class="upload-task-header">
  158. <text style="color:#42b983;">上传成功</text>
  159. </view>
  160. <uploadTask :uploadTasks="uploadSuccessTasks" :showProgress="false"></uploadTask>
  161. </view>
  162. </scroll-view>
  163. </uni-drawer>
  164. <!-- #endif -->
  165. <!-- #ifndef H5 -->
  166. <fix-window />
  167. <!-- #endif -->
  168. </view>
  169. </template>
  170. <script>
  171. import {
  172. mapfields,
  173. stringifyQuery,
  174. getTimeOfSomeDayAgo,
  175. division,
  176. format,
  177. formatDate,
  178. parseDateTime,
  179. fileToUrl,
  180. debounce,
  181. getAllDateCN,
  182. createUniStatQuery
  183. } from '@/js_sdk/uni-stat/util.js'
  184. import {
  185. fieldsMap,
  186. popupFieldsMap
  187. } from './fieldsMap.js'
  188. import uploadTask from './uploadTask.vue'
  189. import {
  190. stacktracey,
  191. uniStracktraceyPreset
  192. } from '@dcloudio/uni-stacktracey';
  193. import adminConfig from '@/admin.config.js'
  194. const appPlatforms = ['ios', 'android', 'app']
  195. const panelOption = [{
  196. title: '错误总数',
  197. value: 0,
  198. tooltip: '指应用在某个时间段内出现错误的总数'
  199. }, {
  200. title: '错误率',
  201. value: 0,
  202. tooltip: '时间范围内的总错误数/应用启动次数,如果小于0.01%,默认显示为0'
  203. }]
  204. export default {
  205. data() {
  206. return {
  207. uniStat: adminConfig.uniStat,
  208. fieldsMap,
  209. popupFieldsMap,
  210. query: {
  211. // type: "js",
  212. dimension: "day",
  213. appid: "",
  214. platform_id: '',
  215. uni_platform: '',
  216. version_id: '',
  217. start_time: []
  218. },
  219. uploadOptions: createUniStatQuery({
  220. appid: "",
  221. uni_platform: '',
  222. }),
  223. uploadMsg: '',
  224. options: {
  225. pageSize: 20,
  226. pageCurrent: 1, // 当前页
  227. total: 0, // 数据总量
  228. },
  229. loading: false,
  230. popupLoading: false,
  231. currentDateTab: 0,
  232. // currentChartTab: ,
  233. tableData: [],
  234. popupTableData: [],
  235. panelData: JSON.parse(JSON.stringify(panelOption)),
  236. chartData: {},
  237. chartTab: 'errorCount',
  238. chartTabs: [{
  239. _id: 'errorCount',
  240. name: '错误次数'
  241. }, {
  242. _id: 'errorRate',
  243. name: '错误率'
  244. }],
  245. errMsg: '',
  246. msgLoading: false,
  247. uploadFile: {
  248. tempFileTasks: [],
  249. tempFiles: [],
  250. clear() {
  251. this.tempFileTasks.length = this.tempFiles.length = 0
  252. }
  253. },
  254. uploadSuccessTaskNames: [],
  255. errorItem: ''
  256. }
  257. },
  258. components: {
  259. uploadTask
  260. },
  261. computed: {
  262. queryStr() {
  263. return stringifyQuery(this.query)
  264. },
  265. versionQuery() {
  266. const {
  267. appid,
  268. uni_platform
  269. } = this.query
  270. const query = stringifyQuery(createUniStatQuery({
  271. appid,
  272. uni_platform
  273. }))
  274. return query
  275. },
  276. uploadVersionQuery() {
  277. const {
  278. appid,
  279. uni_platform
  280. } = this.uploadOptions
  281. const query = stringifyQuery(createUniStatQuery({
  282. appid,
  283. uni_platform
  284. }))
  285. return query
  286. },
  287. vaildate() {
  288. // 检验 this.uploadOptions 所有项都有值
  289. const allItemHasVaule = Object.keys(this.uploadOptions).every(k => this.uploadOptions[k])
  290. if (allItemHasVaule && this.uploadMsg) {
  291. this.uploadMsg = ''
  292. }
  293. return allItemHasVaule
  294. },
  295. uploadSuccessTasks() {
  296. return this.uploadFile.tempFileTasks.filter(task => task.state === 1)
  297. },
  298. sortUploadFileTempFileTasks() {
  299. return this.uploadFile.tempFileTasks.filter(task => task.state !== 1).sort((a, b) => a.state - b.state)
  300. },
  301. sourceMapEnabled() {
  302. return !!this.uniStat.uploadSourceMapCloudSpaceId
  303. }
  304. },
  305. created() {
  306. this.parsedErrors = {}
  307. if (this.sourceMapEnabled) {
  308. // sourceMap 功能需初始化上传的目标云空间
  309. this.uploadSourcemapCloud = uniCloud.init({
  310. provider: 'tencent',
  311. spaceId: this.uniStat.uploadSourceMapCloudSpaceId
  312. })
  313. }
  314. },
  315. watch: {
  316. query: {
  317. deep: true,
  318. handler(val, old) {
  319. this.options.pageCurrent = 1 // 重置分页
  320. this.debounceGet()
  321. }
  322. },
  323. chartTab(val) {
  324. this.getChartData(this.queryStr)
  325. }
  326. },
  327. methods: {
  328. debounceGet: debounce(function() {
  329. this.getAllData(this.queryStr)
  330. }),
  331. useDatetimePicker(res) {
  332. this.currentDateTab = -1
  333. },
  334. changePlatform(id, index, name, item) {
  335. this.query.version_id = 0
  336. this.uploadOptions.uni_platform = item.code
  337. this.query.uni_platform = item.code
  338. },
  339. changeTimeRange(id, index) {
  340. this.currentDateTab = index
  341. const start = getTimeOfSomeDayAgo(id),
  342. end = getTimeOfSomeDayAgo(0) - 1
  343. this.query.start_time = [start, end]
  344. },
  345. changePageCurrent(e) {
  346. this.options.pageCurrent = e.current
  347. this.getTableData(this.queryStr)
  348. },
  349. changePageSize(pageSize) {
  350. this.options.pageSize = pageSize
  351. this.options.pageCurrent = 1 // 重置分页
  352. this.getTableData(this.queryStr)
  353. },
  354. getAllData(query) {
  355. this.getChartData(query)
  356. this.getTableData(query)
  357. },
  358. getChartData(query, field = 'day_count') {
  359. let querystr = stringifyQuery(this.query, false, ['uni_platform'])
  360. this.chartData = {}
  361. const {
  362. pageCurrent
  363. } = this.options
  364. const db = uniCloud.database()
  365. const [start_time, end_tiem] = this.query.start_time
  366. const timeAll = getAllDateCN(new Date(start_time), new Date(end_tiem))
  367. db.collection('uni-stat-error-result')
  368. .where(querystr)
  369. .groupBy('start_time')
  370. .groupField('sum(count) as total_day_count')
  371. .orderBy('start_time', 'desc')
  372. .get({
  373. getCount: true
  374. })
  375. .then(async res => {
  376. const count = res.result.count
  377. const resData = res.result.data
  378. let data = []
  379. console.log("timeAll: ", timeAll);
  380. console.log("resData: ", resData);
  381. timeAll.forEach(v => {
  382. let item = resData.find(item => item.start_time === v)
  383. console.log(item);
  384. if (item) {
  385. data.push(item)
  386. } else {
  387. data.push({
  388. start_time: v,
  389. total_day_count: 0
  390. })
  391. }
  392. })
  393. console.log('----data', data);
  394. const options = {
  395. categories: [],
  396. series: [{
  397. name: '暂无数据',
  398. data: []
  399. }]
  400. }
  401. if (this.chartTab === 'errorCount') {
  402. const countLine = options.series[0] = {
  403. name: '错误次数',
  404. data: []
  405. }
  406. const xAxis = options.categories
  407. for (const item of data) {
  408. let date = item.start_time
  409. const x = formatDate(date, 'day')
  410. const countY = item[`total_${field}`]
  411. xAxis.push(x)
  412. countLine.data.push(countY)
  413. }
  414. this.chartData = options
  415. } else {
  416. let dayAppLaunchs = await this.getDayLaunch(querystr)
  417. console.log('++++', dayAppLaunchs);
  418. const rateLine = options.series[0] = {
  419. name: '错误率(%)',
  420. data: [],
  421. lineStyle: {
  422. color: '#EE6666',
  423. width: 1,
  424. },
  425. itemStyle: {
  426. borderWidth: 1,
  427. borderColor: '#EE6666',
  428. color: '#EE6666'
  429. },
  430. areaStyle: {
  431. color: {
  432. colorStops: [{
  433. offset: 0,
  434. color: '#EE6666', // 0% 处的颜色
  435. }, {
  436. offset: 1,
  437. color: '#FFFFFF' // 100% 处的颜色
  438. }]
  439. }
  440. }
  441. }
  442. const xAxis = options.categories
  443. for (const item of data) {
  444. let date = item.start_time
  445. const x = formatDate(date, 'day')
  446. const countY = item[`total_${field}`]
  447. xAxis.push(x)
  448. if (dayAppLaunchs.length) {
  449. const day = dayAppLaunchs.find(day => day.start_time === item.start_time)
  450. const index = xAxis.indexOf(x)
  451. if (day) {
  452. let rateY = (countY * 100) / day.day_app_launch_count
  453. rateY = rateY.toFixed(2)
  454. rateLine.data[index] = rateY
  455. } else {
  456. rateLine.data[index] = 0
  457. }
  458. }
  459. }
  460. this.chartData = options
  461. }
  462. }).catch((err) => {
  463. console.error(err)
  464. // err.message 错误信息
  465. // err.code 错误码
  466. }).finally(() => {})
  467. },
  468. getTotalCount(query) {
  469. const db = uniCloud.database()
  470. return db.collection('uni-stat-error-result')
  471. .where(query)
  472. .groupBy('appid')
  473. .groupField('sum(count) as total_count')
  474. .get()
  475. },
  476. getTotalLaunch(query) {
  477. const db = uniCloud.database()
  478. return db.collection('uni-stat-result')
  479. .where(query)
  480. .groupBy('appid')
  481. .groupField('sum(app_launch_count) as total_app_launch_count')
  482. .get()
  483. },
  484. /**
  485. * 从结果表里获取范围时间内的启动次数
  486. * @param {Object} query
  487. */
  488. async getDayLaunch(query) {
  489. console.log(query);
  490. const db = uniCloud.database()
  491. const res = await db.collection('uni-stat-result')
  492. .where(query)
  493. .groupBy('start_time')
  494. .groupField('sum(app_launch_count) as day_app_launch_count')
  495. .orderBy('start_time', 'asc')
  496. .get()
  497. return res.result.data || []
  498. },
  499. getTableData(query = stringifyQuery(this.query)) {
  500. let querystr = stringifyQuery(this.query, false, ['uni_platform'])
  501. const {
  502. pageCurrent
  503. } = this.options
  504. this.loading = true
  505. const db = uniCloud.database()
  506. const filterAppid = stringifyQuery(createUniStatQuery({
  507. appid: this.query.appid
  508. }))
  509. const mainTableTemp = db.collection('uni-stat-error-result').where(querystr).getTemp()
  510. const versions = db.collection('opendb-app-versions')
  511. .where(filterAppid)
  512. .getTemp()
  513. const platforms = db.collection('uni-stat-app-platforms')
  514. .getTemp()
  515. db.collection(mainTableTemp, versions, platforms)
  516. .orderBy('count', 'desc')
  517. .skip((pageCurrent - 1) * this.options.pageSize)
  518. .limit(this.options.pageSize)
  519. .get({
  520. getCount: true
  521. })
  522. .then(res => {
  523. const {
  524. count,
  525. data
  526. } = res.result
  527. const tempData = []
  528. this.panelData = JSON.parse(JSON.stringify(panelOption))
  529. for (const item of data) {
  530. item.last_time = parseDateTime(item.last_time, 'dateTime')
  531. item.msgTooltip = item.msg
  532. item.msg = !item.msg ? '' : item.msg.substring(0, 100) + '...'
  533. const v = item.version_id[0]
  534. const p = item.platform_id[0]
  535. item.version = v && v.version
  536. item.platform = p && p.name
  537. item.platform_code = p && p.code
  538. tempData.push(item)
  539. }
  540. this.getTotalCount(querystr).then(res => {
  541. const total = res.result.data[0]
  542. const total_count = total && total.total_count
  543. if (total_count) {
  544. tempData.forEach(item => item.total_count = Number(total_count))
  545. this.panelData[0].value = total_count
  546. }
  547. let launch_count = ''
  548. this.getTotalLaunch(querystr).then(res => {
  549. const total = res.result.data[0]
  550. launch_count = total && total.total_app_launch_count
  551. if (total_count && launch_count) {
  552. let errorRate = total_count / launch_count
  553. errorRate = (errorRate * 100).toFixed(2) + '%'
  554. this.panelData[1].value = errorRate
  555. }
  556. })
  557. }).finally(() => {
  558. this.tableData = []
  559. this.options.total = count
  560. tempData.forEach(item => mapfields(fieldsMap, item, item))
  561. this.tableData = tempData
  562. })
  563. }).catch((err) => {
  564. console.error(err)
  565. // err.message 错误信息
  566. // err.code 错误码
  567. }).finally(() => {
  568. this.loading = false
  569. })
  570. },
  571. navTo(url, item) {
  572. if (url.indexOf('http') > -1) {
  573. window.open(url)
  574. } else {
  575. if (item) {
  576. url = `${url}?error_hash=${item.hash}&create_time=${item.start_time}`
  577. }
  578. uni.navigateTo({
  579. url
  580. })
  581. }
  582. },
  583. getPlatform(platform_id) {
  584. const platforms = uni.getStorageSync('platform_last_data')
  585. let platform = Array.isArray(platforms) && platforms.find(p => p._id === platform_id).code
  586. // if (appPlatforms.indexOf(platform) !== -1) platform = 'app'
  587. return platform
  588. },
  589. getVersion(version_id) {
  590. const versions = uni.getStorageSync('uni-stat-app-versions_last_data')
  591. const version = Array.isArray(versions) && versions.find(v => v._id === version_id).text
  592. return version
  593. },
  594. closeErrPopup() {
  595. this.$refs.errMsg.close()
  596. },
  597. errMsgPopupChange(res) {
  598. if (res.show) {
  599. const err = this.errorItem.msgTooltip
  600. if (this.msgLoading) {
  601. this.closeErrPopup()
  602. return;
  603. }
  604. if (!err) {
  605. this.errMsg = '暂无错误数据'
  606. }
  607. this.errMsg = ''
  608. const oldMsg = this.parsedErrors[err]
  609. // || oldMsg === err
  610. this.msgLoading = true
  611. this.parseError(this.errorItem)
  612. return
  613. if (!oldMsg) {
  614. this.msgLoading = true
  615. this.parseError(this.errorItem)
  616. } else {
  617. this.errMsg = oldMsg
  618. }
  619. } else {
  620. this.msgLoading = false
  621. }
  622. },
  623. parseError(item) {
  624. let {
  625. msgTooltip: err,
  626. appid,
  627. platform_code,
  628. version
  629. } = item
  630. let base = this.uniStat.cloudSourceMapUrl + `/${appid}/${platform_code}/${version}/`
  631. try {
  632. err = JSON.parse(err)
  633. } catch (e) {}
  634. console.log("originalErrMsg: ", err);
  635. stacktracey(err, {
  636. preset: uniStracktraceyPreset({
  637. base,
  638. uniPlatform: platform_code,
  639. splitThirdParty: true
  640. })
  641. }).then(res => {
  642. const {
  643. userError,
  644. thirdParty
  645. } = res
  646. const separate = userError.length && thirdParty.length ?
  647. `\n\n------------${platform_code.indexOf('mp-') !== -1 ? platform_code : 'uni-app'} runtime error------------\n\n` :
  648. ''
  649. this.errMsg = `${userError}${separate}${thirdParty}`
  650. this.parsedErrors[err] = this.errMsg
  651. }).finally(() => {
  652. this.msgLoading = false
  653. });
  654. },
  655. openUploadPopup() {
  656. const {
  657. appid,
  658. uni_platform
  659. } = this.query
  660. this.uploadOptions = {
  661. appid,
  662. uni_platform
  663. }
  664. this.$refs.upload.open()
  665. },
  666. closeUploadPopup() {
  667. this.$refs.upload.close()
  668. },
  669. createUploadFileTask(prefix, fileDiskPath, filePath, onUploadProgress) {
  670. const cloudPath = prefix + fileDiskPath
  671. return this.uploadSourcemapCloud.uploadFile({
  672. filePath,
  673. cloudPath,
  674. onUploadProgress
  675. })
  676. },
  677. choosefile() {
  678. if (!this.vaildate) {
  679. this.uploadMsg = '请先将应用、平台、版本填写完整'
  680. return
  681. }
  682. const {
  683. appid,
  684. uni_platform,
  685. version
  686. } = this.uploadOptions
  687. const prefix = `__UNI__/uni-stat/sourcemap/${appid}/${uni_platform}/${version}/`
  688. console.log('...........prefix', prefix);
  689. // 原生 input 上传逻辑
  690. const inputEl = document.createElement('input')
  691. inputEl.type = 'file'
  692. inputEl.directory = true
  693. inputEl.webkitdirectory = true
  694. inputEl.click()
  695. inputEl.addEventListener('change', () => {
  696. this.uploadFile.clear()
  697. const fileList = inputEl.files; /* now you can work with the file list */
  698. if (!fileList.length) return
  699. Array.prototype.forEach.call(fileList, (file) => {
  700. const path = fileToUrl(file)
  701. this.uploadFile.tempFileTasks.push({
  702. fileDiskPath: file.webkitRelativePath.split('/').slice(1).join('/'),
  703. path,
  704. size: `${(file.size / 1024).toFixed(2)}kb`,
  705. name: file.name,
  706. state: 0,
  707. progress: 0
  708. })
  709. Object.defineProperty(file, 'path', {
  710. get() {
  711. return path
  712. },
  713. })
  714. this.uploadFile.tempFiles.push(file)
  715. })
  716. this.uploadFile.tempFileTasks.reduce((_uploadFilePromise, cur, curIndex) => {
  717. return _uploadFilePromise
  718. .then((msg) => {
  719. return new Promise((resolve, reject) => {
  720. // 已上传的文件
  721. if (this.uploadSuccessTaskNames.indexOf(cur.name) !== -1) {
  722. cur.progress = 1
  723. setTimeout(() => {
  724. cur.state = 1
  725. resolve()
  726. }, 200)
  727. } else {
  728. this.createUploadFileTask(
  729. prefix,
  730. cur.fileDiskPath,
  731. cur.path,
  732. (OnUploadProgressRes) => {
  733. const {
  734. loaded,
  735. total
  736. } = OnUploadProgressRes
  737. cur.progress = loaded / total
  738. }
  739. ).then(() => {
  740. setTimeout(() => {
  741. this.uploadSuccessTaskNames
  742. .push(cur.name)
  743. cur.state = 1
  744. resolve()
  745. }, 500)
  746. }).catch((err) => {
  747. cur.state = -1
  748. reject(`${cur.name} 上传失败:` + JSON
  749. .stringify(err))
  750. })
  751. }
  752. })
  753. })
  754. }, Promise.resolve())
  755. })
  756. },
  757. createStr(maps, fn, prefix = 'total_') {
  758. const strArr = []
  759. maps.forEach(mapper => {
  760. if (field.hasOwnProperty('value')) {
  761. const fieldName = mapper.field
  762. strArr.push(`${fn}(${fieldName}) as ${prefix + fieldName}`)
  763. }
  764. })
  765. return strArr.join()
  766. },
  767. openErrPopup(item) {
  768. this.errorItem = item
  769. this.$refs.errMsg.open()
  770. }
  771. }
  772. }
  773. </script>
  774. <style>
  775. .flex-between {
  776. margin-bottom: 10px;
  777. display: flex;
  778. justify-content: space-between;
  779. align-items: center;
  780. }
  781. .uni-stat-panel {
  782. box-shadow: unset;
  783. border-bottom: 1px solid #eee;
  784. padding: 0;
  785. margin: 0 15px;
  786. }
  787. .uni-stat-tooltip-s {
  788. width: 160px;
  789. white-space: normal;
  790. }
  791. .black-theme {
  792. background-color: #333;
  793. color: #fff;
  794. }
  795. .dialog-close {
  796. cursor: pointer;
  797. position: absolute;
  798. top: 0;
  799. right: 0;
  800. /* #ifndef APP-NVUE */
  801. display: flex;
  802. /* #endif */
  803. flex-direction: row;
  804. align-items: center;
  805. padding: 20px;
  806. margin-top: 10px;
  807. }
  808. .dialog-close-plus {
  809. width: 20px;
  810. height: 2px;
  811. background-color: #fff;
  812. border-radius: 2px;
  813. transform: rotate(45deg);
  814. }
  815. .dialog-close-rotate {
  816. position: absolute;
  817. transform: rotate(-45deg);
  818. }
  819. .upload-msg-warning {
  820. padding: 0px 15px;
  821. color: red;
  822. font-size: 14px;
  823. }
  824. ::v-deep .sourcemap-drawser .uni-select {
  825. flex: 1;
  826. }
  827. ::v-deep .sourcemap-drawser .uni-select .uni-select__input-text {
  828. width: 100%;
  829. }
  830. .upload-task-header {
  831. font-size: 14px;
  832. color: #666;
  833. padding: 15rpx 25rpx;
  834. border-top: 1px solid #eee;
  835. border-bottom: 1px solid #eee;
  836. }
  837. </style>