index.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. 'use strict'
  2. /* eslint-disable no-undef */
  3. window.onload = function() {
  4. pageLoad() // 初始化页面
  5. fileInfo() // 页面转换详情
  6. maskClose() // 关闭弹窗
  7. }
  8. function pageLoad() {
  9. projectResult()
  10. concepteleMade() // 汇总
  11. temelatetable()
  12. openingMade()
  13. supportiveness()
  14. footerMade()
  15. }
  16. // 汇总
  17. function concepteleMade() {
  18. let conceptele = ''
  19. conceptele = `<div class="itembox">\n <div class="topname">\u603B\u6570</div>\n <div class="botval">${pageData.concept.modelAll}</div>\n </div>\n <div class="itembox">\n <div class="topname">\u5B8C\u5168\u8F6C\u6362<i class="iconfont icon-zhengque"></i></div>\n <div class="botval">${pageData.concept.completely}</div>\n </div>\n <div class="itembox">\n <div class="topname">\u90E8\u5206\u8F6C\u6362<i class="iconfont icon-warning"></i></div>\n <div class="botval">${pageData.concept.partial}</div>\n </div>\n <div class="itembox">\n <div class="topname">\u4E0D\u652F\u6301<i class="iconfont icon-cuowu"></i></div>\n <div class="botval">${pageData.concept.notsupport}</div>\n </div>`
  20. const circleBox = document.querySelector('.rep-allbox')
  21. circleBox.innerHTML = conceptele
  22. }
  23. function fileDetails(templete, type) {
  24. const liItemObj = {
  25. templete: '模板文件',
  26. jsonModular: 'json文件',
  27. otherModular: '其他文件',
  28. jsModular: '脚本文件',
  29. wxssModular: '样式文件',
  30. modularWxs: '自定义脚本',
  31. unsupported: '不支持文件',
  32. supportPart: '部分支持',
  33. }
  34. let keyArr = Object.keys(templete)
  35. if (keyArr.length === 0) {
  36. return false
  37. }
  38. const tabBox = document.querySelector('.tab-box')
  39. const ulBox = tabBox.querySelector('.ul')
  40. const firstLi = ulBox.querySelectorAll('li')[0]
  41. if (firstLi) {
  42. firstLi.classList.add('actived')
  43. }
  44. const liItem = document.createElement('li')
  45. liItem.classList.add('tab-item')
  46. liItem.setAttribute('data-type', type)
  47. liItem.innerHTML = liItemObj[type]
  48. ulBox.appendChild(liItem)
  49. const cardBox = tabBox.querySelector('.card-box')
  50. const firstCard = cardBox.querySelectorAll('.table-info')[0]
  51. if (firstCard) {
  52. firstCard.classList.add('actived')
  53. }
  54. const tableInfo = document.createElement('div')
  55. tableInfo.classList.add('table-info')
  56. tableInfo.classList.add(type)
  57. const table = document.createElement('table')
  58. table.classList.add('table')
  59. const thead = document.createElement('thead')
  60. thead.classList.add('table-head')
  61. thead.innerHTML = '<tr class="pages">\n <th>\u6587\u4EF6\u8DEF\u5F84</th>\n <th>\u8F6C\u6362\u7ED3\u679C</th>\n </tr>'
  62. const tbody = document.createElement('tbody')
  63. let tbodyData = ''
  64. let unsupportedNum = 0
  65. // 排序
  66. const warningArr = []
  67. const errorArr = []
  68. const successArr = []
  69. keyArr.forEach((key) => {
  70. if (templete[key].status === 1) {
  71. successArr.push(key)
  72. } else if (templete[key].status === 2) {
  73. warningArr.push(key)
  74. } else if (templete[key].status === 3) {
  75. errorArr.push(key)
  76. }
  77. })
  78. keyArr = errorArr.concat(warningArr).concat(successArr)
  79. let spanColor = 'warn'
  80. keyArr.forEach((key) => {
  81. let icon = ''
  82. if (templete[key].status === 1) {
  83. icon = '<i class="iconfont icon-zhengque"></i>'
  84. } else if (templete[key].status === 2) {
  85. icon = '<i class="iconfont icon-warning"></i>'
  86. } else if (templete[key].status === 3) {
  87. icon = '<i class="iconfont icon-cuowu"></i>'
  88. }
  89. tbodyData = `${tbodyData}<tr>\n <td class="file-path">\n ${key}\n </td>\n \n <td class="apges">\n ${icon}\n </td>\n </tr>`
  90. if (templete[key].supportType && templete[key].supportType !== 1) {
  91. unsupportedNum++
  92. }
  93. if (templete[key].supportType === 3) {
  94. spanColor = 'err'
  95. }
  96. })
  97. tbody.innerHTML = tbodyData
  98. const span = document.createElement('span')
  99. span.classList.add('num')
  100. liItem.appendChild(span)
  101. unsupportedNum = unsupportedNum || ''
  102. spanColor = unsupportedNum ? spanColor : 'none'
  103. span.innerHTML = unsupportedNum
  104. span.classList.add(spanColor)
  105. table.appendChild(thead)
  106. table.appendChild(tbody)
  107. tableInfo.appendChild(table)
  108. cardBox.appendChild(tableInfo)
  109. liItem.addEventListener('click', () => {
  110. ulBox.querySelectorAll('li').forEach((ele) => {
  111. ele.classList.remove('actived')
  112. })
  113. cardBox.querySelectorAll('.table-info').forEach((ele) => {
  114. ele.classList.remove('actived')
  115. })
  116. const cardName = liItem.getAttribute('data-type')
  117. cardBox.querySelector(`.${cardName}`).classList.add('actived')
  118. liItem.classList.add('actived')
  119. })
  120. }
  121. function openingMade() {
  122. const openingData = pageData.opening
  123. const keyArr = Object.keys(openingData)
  124. if (keyArr.length === 0) {
  125. return false
  126. }
  127. const tabBox = document.querySelector('.tab-box')
  128. const ulBox = tabBox.querySelector('.ul')
  129. const firstLi = ulBox.querySelectorAll('li')[0]
  130. if (firstLi) {
  131. firstLi.classList.add('actived')
  132. }
  133. const liItem = document.createElement('li')
  134. const span = document.createElement('span')
  135. span.classList.add('num')
  136. liItem.classList.add('tab-item')
  137. liItem.setAttribute('data-type', 'openability')
  138. liItem.innerHTML = '开放能力'
  139. ulBox.appendChild(liItem)
  140. const cardBox = tabBox.querySelector('.card-box')
  141. const firstCard = cardBox.querySelectorAll('.table-info')[0]
  142. if (firstCard) {
  143. firstCard.classList.add('actived')
  144. }
  145. const tableInfo = document.createElement('div')
  146. tableInfo.classList.add('table-info')
  147. tableInfo.classList.add('openability')
  148. const table = document.createElement('table')
  149. table.classList.add('table')
  150. const thead = document.createElement('thead')
  151. thead.classList.add('table-head')
  152. thead.innerHTML = '<tr>\n <th>\u80FD\u529B\u540D\u79F0</th>\n <th>\u9875\u9762\u8DEF\u5F84</th>\n <th>\u5982\u4F55\u89E3\u51B3</th>\n <th>\u8F6C\u6362\u7ED3\u679C</th>\n </tr>'
  153. const tbody = document.createElement('tbody')
  154. let tbodyData = ''
  155. let unsupportedNum = 0
  156. let spanColor = 'warn'
  157. // 排序
  158. const zhengqueArr = keyArr.filter((key) => {
  159. return openingData[key].status === 1
  160. })
  161. const warningArr = keyArr.filter((key) => {
  162. return openingData[key].status === 2
  163. })
  164. const cuowuArr = keyArr.filter((key) => {
  165. return openingData[key].status === 3
  166. })
  167. const newKeyArr = cuowuArr.concat(warningArr, zhengqueArr)
  168. newKeyArr.forEach((key) => {
  169. let icon = ''
  170. if (openingData[key].status === 1) {
  171. icon = '<i class="iconfont icon-zhengque"></i>'
  172. } else if (openingData[key].status === 2) {
  173. icon = '<i class="iconfont icon-warning"></i>'
  174. } else if (openingData[key].status === 3) {
  175. icon = '<i class="iconfont icon-cuowu"></i>'
  176. }
  177. tbodyData = `${tbodyData}<tr>\n <td>${key}</td>\n <td>${openingData[key].pathArr.join('、')}</td>\n <td>\n <div class="show-instruct" data-path="${openingData[key].docpath}">\n \u67E5\u770B\u76F8\u5173\u80FD\u529B\n </div>\n </td>\n \n <td class="apges">\n ${icon}\n </td>\n </tr>`
  178. if (openingData[key].status !== 1) {
  179. unsupportedNum++
  180. }
  181. if (openingData[key].status === 3) {
  182. spanColor = 'err'
  183. }
  184. })
  185. unsupportedNum = unsupportedNum || ''
  186. spanColor = unsupportedNum ? spanColor : 'none'
  187. span.innerText = unsupportedNum
  188. span.classList.add(spanColor)
  189. liItem.appendChild(span)
  190. tbody.innerHTML = tbodyData
  191. table.appendChild(thead)
  192. table.appendChild(tbody)
  193. tableInfo.appendChild(table)
  194. cardBox.appendChild(tableInfo)
  195. liItem.addEventListener('click', () => {
  196. ulBox.querySelectorAll('li').forEach((ele) => {
  197. ele.classList.remove('actived')
  198. })
  199. cardBox.querySelectorAll('.table-info').forEach((ele) => {
  200. ele.classList.remove('actived')
  201. })
  202. cardBox.querySelector('.openability').classList.add('actived')
  203. liItem.classList.add('actived')
  204. cardBox.querySelectorAll('.show-instruct').forEach((ele) => {
  205. ele.addEventListener('click', () => {
  206. const path = ele.getAttribute('data-path')
  207. window.location.href = path
  208. })
  209. })
  210. })
  211. }
  212. function supportiveness() {
  213. const supportPart = {}
  214. const unsupported = {}
  215. Object.keys(pageData.transforms).forEach((key) => {
  216. if (pageData.transforms[key].status === 2) {
  217. supportPart[key] = pageData.transforms[key]
  218. }
  219. if (pageData.transforms[key].status === 3) {
  220. unsupported[key] = pageData.transforms[key]
  221. }
  222. })
  223. fileDetails(supportPart, 'supportPart')
  224. fileDetails(unsupported, 'unsupported')
  225. }
  226. function temelatetable() {
  227. const templete = {}
  228. const jsModular = {}
  229. const wxssModular = {}
  230. const jsonModular = {}
  231. const modularWxs = {}
  232. const otherModular = {}
  233. for (const key in pageData.transforms) {
  234. if (pageData.transforms[key].type === 'templete') {
  235. templete[key] = Object.assign({}, pageData.transforms[key])
  236. templete[key].supportType = templete[key].status
  237. } else if (pageData.transforms[key].type === 'jsModular') {
  238. jsModular[key] = Object.assign({}, pageData.transforms[key])
  239. jsModular[key].supportType = jsModular[key].status
  240. } else if (pageData.transforms[key].type === 'wxssModular') {
  241. wxssModular[key] = Object.assign({}, pageData.transforms[key])
  242. wxssModular[key].supportType = wxssModular[key].status
  243. } else if (pageData.transforms[key].type === 'jsonModular') {
  244. jsonModular[key] = Object.assign({}, pageData.transforms[key])
  245. jsonModular[key].supportType = jsonModular[key].status
  246. } else if (pageData.transforms[key].type === 'otherModular') {
  247. otherModular[key] = Object.assign({}, pageData.transforms[key])
  248. otherModular[key].supportType = otherModular[key].status
  249. } else if (pageData.transforms[key].type === 'modularWxs') {
  250. modularWxs[key] = Object.assign({}, pageData.transforms[key])
  251. modularWxs[key].supportType = modularWxs[key].status
  252. }
  253. }
  254. fileDetails(templete, 'templete')
  255. fileDetails(jsModular, 'jsModular')
  256. fileDetails(wxssModular, 'wxssModular')
  257. fileDetails(jsonModular, 'jsonModular')
  258. fileDetails(otherModular, 'otherModular')
  259. fileDetails(modularWxs, 'modularWxs')
  260. }
  261. function fileInfo() {
  262. const mask = document.querySelector('.mask')
  263. const maskTitle = mask.querySelector('.title')
  264. const pagePath = document.querySelectorAll('.file-path')
  265. const tableBox = mask.querySelector('.table-box')
  266. pagePath.forEach((ele) => {
  267. ele.addEventListener('click', () => {
  268. if (pageData.transforms[ele.innerText].type === 'templete') {
  269. tableBox.querySelector('#col1').innerText = '组件名'
  270. tableBox.querySelector('#col2').innerText = '不支持'
  271. } else if (pageData.transforms[ele.innerText].type === 'jsModular') {
  272. tableBox.querySelector('#col1').innerText = 'api/生命周期'
  273. tableBox.querySelector('#col2').innerText = '不支持的部分(参数/返回值)'
  274. } else if (pageData.transforms[ele.innerText].type === 'otherModular') {
  275. if (ele.innerText.indexOf('.js') !== -1) {
  276. tableBox.querySelector('#col1').innerText = 'api/生命周期'
  277. tableBox.querySelector('#col2').innerText = '不支持的部分(参数/返回值)'
  278. } else {
  279. tableBox.querySelector('#col1').style = 'display:none'
  280. tableBox.querySelector('#col2').style = 'display:none'
  281. tableBox.querySelector('#col3').style = 'display:none'
  282. }
  283. } else if (pageData.transforms[ele.innerText].type === 'jsonModular') {
  284. tableBox.querySelector('#col1').innerText = '属性名称'
  285. tableBox.querySelector('#col2').innerText = '支持程度'
  286. if (ele.innerText === 'app.json') {
  287. tableBox.querySelector('#col2').innerText = '不支持子属性'
  288. }
  289. }
  290. maskTitle.innerText = ele.innerText
  291. const myTbody = tableBox.querySelector('tbody')
  292. if (pageData.transforms[ele.innerText].components.length > 0) {
  293. pageData.transforms[ele.innerText].components.forEach((item) => {
  294. const newtr = document.createElement('tr')
  295. let newtrStr = ''
  296. let opations = ''
  297. item.attrs.forEach((its) => {
  298. opations += `<div class="opation-item">\n ${its}\n </div>`
  299. })
  300. if (item.doc) {
  301. if (item.doc !== '无') {
  302. newtrStr += `<td class="name">\n ${item.name}\n </td>\n <td class="opations">\n ${opations}\n </td>\n <td class="result" path="${item.doc}">\n \u5E2E\u52A9\u6587\u6863\n </td>`
  303. } else {
  304. newtrStr += `<td class="name">\n ${item.name}\n </td>\n <td class="opations">\n ${opations}\n </td>\n <td class="unsupported" path="">\n \u6682\u4E0D\u652F\u6301\uFF0C\u8BF7\u5C1D\u8BD5\u5176\u4ED6\u5B9E\u73B0\u65B9\u5F0F\n </td>`
  305. }
  306. } else {
  307. newtrStr += `<td class="name">\n ${item.name}\n </td>\n <td class="opations">\n ${opations}\n </td>\n <td class="unsupported">\n \u6682\u4E0D\u652F\u6301\uFF0C\u8BF7\u5C1D\u8BD5\u5176\u4ED6\u5B9E\u73B0\u65B9\u5F0F\n </td>`
  308. }
  309. newtr.innerHTML = newtrStr
  310. myTbody.appendChild(newtr)
  311. })
  312. } else {
  313. let newtrStr = ''
  314. const newtr = document.createElement('tr')
  315. newtrStr = '<td class="name" colspan="3">\n \u5B8C\u6574\u652F\u6301\n </td>'
  316. newtr.innerHTML = newtrStr
  317. myTbody.appendChild(newtr)
  318. }
  319. mask.classList.remove('hide')
  320. const helpDoc = mask.querySelectorAll('.result')
  321. helpDoc.forEach((_ele) => {
  322. _ele.addEventListener('click', function() {
  323. const path = this.getAttribute('path')
  324. window.open(path)
  325. })
  326. })
  327. })
  328. })
  329. }
  330. function maskClose() {
  331. const mask = document.querySelector('.mask')
  332. const tableBox = mask.querySelector('.table-box')
  333. mask.querySelector('.close').addEventListener('click', () => {
  334. tableBox.querySelector('table').innerHTML = '<thead>\n <tr>\n <th class="name header" id="col1">\u7EC4\u4EF6\u540D</th>\n <th class="opations header" id="col2">\u4E0D\u652F\u6301</th>\n <th class="result header" id="col3">\u5982\u4F55\u89E3\u51B3</th>\n </tr>\n </thead>\n <tbody>\n </tbody>'
  335. mask.classList.add('hide')
  336. })
  337. }
  338. function projectResult() {
  339. const myProject = document.querySelector('#project')
  340. const surroundings = {}
  341. let tableInfo = ''
  342. for (const key in pageData.surroundings) {
  343. if (pageData.surroundings.hasOwnProperty(key)) {
  344. surroundings[pageData.surroundings[key].name] = pageData.surroundings[key].val
  345. }
  346. }
  347. pageData.tableInfo = Object.assign(pageData.tableInfo, surroundings)
  348. Object.keys(pageData.tableInfo).forEach((key) => {
  349. tableInfo = `${tableInfo}<tr>\n <td class="text-left">\n ${key}\n </td>\n <td class="text-right">\n ${pageData.tableInfo[key]}\n </td>\n </tr>`
  350. })
  351. myProject.querySelector('tbody').innerHTML = tableInfo
  352. }
  353. function footerMade() {
  354. document.querySelector('.foot-cont').innerText = `Power by Antmove v${pageData.toolVs}`
  355. }