IndiDocX.js 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584
  1. //reconnect-websocket
  2. ;(function (global, factory) {
  3. if (typeof define === 'function' && define.amd) {
  4. define([], factory)
  5. } else if (typeof module !== 'undefined' && module.exports) {
  6. module.exports = factory()
  7. } else {
  8. global.ReconnectingWebSocket = factory()
  9. }
  10. })(this || window, function () {
  11. if (!('WebSocket' in window)) {
  12. console.warn('此浏览器不支持WebSocket')
  13. return
  14. }
  15. if ('ReconnectingWebSocket' in window) {
  16. return
  17. }
  18. function ReconnectingWebSocket(url, protocols, options) {
  19. // Default settings
  20. var settings = {
  21. /** Whether this instance should log debug messages. */
  22. debug: false,
  23. /** Whether or not the websocket should attempt to connect immediately upon instantiation. */
  24. automaticOpen: true,
  25. /** The number of milliseconds to delay before attempting to reconnect. */
  26. reconnectInterval: 1000,
  27. /** The maximum number of milliseconds to delay a reconnection attempt. */
  28. maxReconnectInterval: 30000,
  29. /** The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. */
  30. reconnectDecay: 1.5,
  31. /** The maximum time in milliseconds to wait for a connection to succeed before closing and retrying. */
  32. timeoutInterval: 2000,
  33. /** The maximum number of reconnection attempts to make. Unlimited if null. */
  34. maxReconnectAttempts: null,
  35. /** The binary type, possible values 'blob' or 'arraybuffer', default 'blob'. */
  36. binaryType: 'blob',
  37. }
  38. if (!options) {
  39. options = {}
  40. }
  41. // Overwrite and define settings with options if they exist.
  42. for (var key in settings) {
  43. if (typeof options[key] !== 'undefined') {
  44. this[key] = options[key]
  45. } else {
  46. this[key] = settings[key]
  47. }
  48. }
  49. // These should be treated as read-only properties
  50. /** The URL as resolved by the constructor. This is always an absolute URL. Read only. */
  51. this.url = url
  52. /** The number of attempted reconnects since starting, or the last successful connection. Read only. */
  53. this.reconnectAttempts = 0
  54. /**
  55. * The current state of the connection.
  56. * Can be one of: WebSocket.CONNECTING, WebSocket.OPEN, WebSocket.CLOSING, WebSocket.CLOSED
  57. * Read only.
  58. */
  59. this.readyState = WebSocket.CONNECTING
  60. /**
  61. * A string indicating the name of the sub-protocol the server selected; this will be one of
  62. * the strings specified in the protocols parameter when creating the WebSocket object.
  63. * Read only.
  64. */
  65. this.protocol = null
  66. // Private state variables
  67. var self = this
  68. var ws
  69. var forcedClose = false
  70. var timedOut = false
  71. var eventTarget = document.createElement('div')
  72. // Wire up "on*" properties as event handlers
  73. eventTarget.addEventListener('open', function (event) {
  74. self.onopen(event)
  75. })
  76. eventTarget.addEventListener('close', function (event) {
  77. self.onclose(event)
  78. })
  79. eventTarget.addEventListener('connecting', function (event) {
  80. self.onconnecting(event)
  81. })
  82. eventTarget.addEventListener('message', function (event) {
  83. self.onmessage(event)
  84. })
  85. eventTarget.addEventListener('error', function (event) {
  86. self.onerror(event)
  87. })
  88. // Expose the API required by EventTarget
  89. this.addEventListener = eventTarget.addEventListener.bind(eventTarget)
  90. this.removeEventListener = eventTarget.removeEventListener.bind(eventTarget)
  91. this.dispatchEvent = eventTarget.dispatchEvent.bind(eventTarget)
  92. /**
  93. * This function generates an event that is compatible with standard
  94. * compliant browsers and IE9 - IE11
  95. *
  96. * This will prevent the error:
  97. * Object doesn't support this action
  98. *
  99. * http://stackoverflow.com/questions/19345392/why-arent-my-parameters-getting-passed-through-to-a-dispatched-event/19345563#19345563
  100. * @param s String The name that the event should use
  101. * @param args Object an optional object that the event will use
  102. */
  103. function generateEvent(s, args) {
  104. var evt = document.createEvent('CustomEvent')
  105. evt.initCustomEvent(s, false, false, args)
  106. return evt
  107. }
  108. this.open = function (reconnectAttempt) {
  109. ws = new WebSocket(self.url, protocols || [])
  110. ws.binaryType = this.binaryType
  111. if (reconnectAttempt) {
  112. if (this.maxReconnectAttempts && this.reconnectAttempts > this.maxReconnectAttempts) {
  113. return
  114. }
  115. } else {
  116. eventTarget.dispatchEvent(generateEvent('connecting'))
  117. this.reconnectAttempts = 0
  118. }
  119. if (self.debug || ReconnectingWebSocket.debugAll) {
  120. console.debug('ReconnectingWebSocket', 'attempt-connect', self.url)
  121. }
  122. var localWs = ws
  123. var timeout = setTimeout(function () {
  124. if (self.debug || ReconnectingWebSocket.debugAll) {
  125. console.debug('ReconnectingWebSocket', 'connection-timeout', self.url)
  126. }
  127. timedOut = true
  128. localWs.close()
  129. timedOut = false
  130. }, self.timeoutInterval)
  131. ws.onopen = function (event) {
  132. clearTimeout(timeout)
  133. if (self.debug || ReconnectingWebSocket.debugAll) {
  134. console.debug('ReconnectingWebSocket', 'onopen', self.url)
  135. }
  136. self.protocol = ws.protocol
  137. self.readyState = WebSocket.OPEN
  138. self.reconnectAttempts = 0
  139. var e = generateEvent('open')
  140. e.isReconnect = reconnectAttempt
  141. reconnectAttempt = false
  142. eventTarget.dispatchEvent(e)
  143. }
  144. ws.onclose = function (event) {
  145. clearTimeout(timeout)
  146. ws = null
  147. if (forcedClose) {
  148. self.readyState = WebSocket.CLOSED
  149. eventTarget.dispatchEvent(generateEvent('close'))
  150. } else {
  151. self.readyState = WebSocket.CONNECTING
  152. var e = generateEvent('connecting')
  153. e.code = event.code
  154. e.reason = event.reason
  155. e.wasClean = event.wasClean
  156. eventTarget.dispatchEvent(e)
  157. if (!reconnectAttempt && !timedOut) {
  158. if (self.debug || ReconnectingWebSocket.debugAll) {
  159. console.debug('ReconnectingWebSocket', 'onclose', self.url)
  160. }
  161. eventTarget.dispatchEvent(generateEvent('close'))
  162. }
  163. var timeout =
  164. self.reconnectInterval * Math.pow(self.reconnectDecay, self.reconnectAttempts)
  165. setTimeout(
  166. function () {
  167. self.reconnectAttempts++
  168. self.open(true)
  169. },
  170. timeout > self.maxReconnectInterval ? self.maxReconnectInterval : timeout
  171. )
  172. }
  173. }
  174. ws.onmessage = function (event) {
  175. if (self.debug || ReconnectingWebSocket.debugAll) {
  176. console.debug('ReconnectingWebSocket', 'onmessage', self.url, event.data)
  177. }
  178. var e = generateEvent('message')
  179. e.data = event.data
  180. eventTarget.dispatchEvent(e)
  181. }
  182. ws.onerror = function (event) {
  183. if (self.debug || ReconnectingWebSocket.debugAll) {
  184. console.debug('ReconnectingWebSocket', 'onerror', self.url, event)
  185. }
  186. eventTarget.dispatchEvent(generateEvent('error'))
  187. }
  188. }
  189. // Whether or not to create a websocket upon instantiation
  190. if (this.automaticOpen == true) {
  191. this.open(false)
  192. }
  193. /**
  194. * Transmits data to the server over the WebSocket connection.
  195. *
  196. * @param data a text string, ArrayBuffer or Blob to send to the server.
  197. */
  198. this.send = function (data) {
  199. if (ws) {
  200. if (self.debug || ReconnectingWebSocket.debugAll) {
  201. console.debug('ReconnectingWebSocket', 'send', self.url, data)
  202. }
  203. return ws.send(data)
  204. } else {
  205. throw 'INVALID_STATE_ERR : Pausing to reconnect websocket'
  206. }
  207. }
  208. /**
  209. * Closes the WebSocket connection or connection attempt, if any.
  210. * If the connection is already CLOSED, this method does nothing.
  211. */
  212. this.close = function (code, reason) {
  213. // Default CLOSE_NORMAL code
  214. if (typeof code == 'undefined') {
  215. code = 1000
  216. }
  217. forcedClose = true
  218. if (ws) {
  219. ws.close(code, reason)
  220. }
  221. }
  222. /**
  223. * Additional public API method to refresh the connection if still open (close, re-open).
  224. * For example, if the app suspects bad data / missed heart beats, it can try to refresh.
  225. */
  226. this.refresh = function () {
  227. if (ws) {
  228. ws.close()
  229. }
  230. }
  231. }
  232. /**
  233. * An event listener to be called when the WebSocket connection's readyState changes to OPEN;
  234. * this indicates that the connection is ready to send and receive data.
  235. */
  236. ReconnectingWebSocket.prototype.onopen = function (event) {}
  237. /** An event listener to be called when the WebSocket connection's readyState changes to CLOSED. */
  238. ReconnectingWebSocket.prototype.onclose = function (event) {}
  239. /** An event listener to be called when a connection begins being attempted. */
  240. ReconnectingWebSocket.prototype.onconnecting = function (event) {}
  241. /** An event listener to be called when a message is received from the server. */
  242. ReconnectingWebSocket.prototype.onmessage = function (event) {}
  243. /** An event listener to be called when an error occurs. */
  244. ReconnectingWebSocket.prototype.onerror = function (event) {}
  245. /**
  246. * Whether all instances of ReconnectingWebSocket should log debug messages.
  247. * Setting this to true is the equivalent of setting all instances of ReconnectingWebSocket.debug to true.
  248. */
  249. ReconnectingWebSocket.debugAll = false
  250. ReconnectingWebSocket.CONNECTING = WebSocket.CONNECTING
  251. ReconnectingWebSocket.OPEN = WebSocket.OPEN
  252. ReconnectingWebSocket.CLOSING = WebSocket.CLOSING
  253. ReconnectingWebSocket.CLOSED = WebSocket.CLOSED
  254. return ReconnectingWebSocket
  255. })
  256. let indidocxModule = {
  257. version: '2023.0412.01',
  258. createInstance(options) {
  259. let indidocxobj = {
  260. //对象属性
  261. slCtl: {
  262. id: 0, //slctl的唯一id
  263. forWindowID: CreateRandomId(),
  264. $$idx: {},
  265. Activation: '',
  266. initPortID: 0,
  267. domain: '127.0.0.1',
  268. curFileType: 'default',
  269. strNeedSaveMark: 'false',
  270. strPageNumUrl: '',
  271. strPageNum: '',
  272. strWaterMarkUrl: '',
  273. strWaterMark: '',
  274. strWaterMarkParam: '',
  275. strPageHeader: '',
  276. strPageHeaderUrl: '',
  277. strSpace: '',
  278. uploadCompentInfoUrl: 'api/framework/v1/indidocx/saveIndidocxMessage',
  279. doTime: new Date(),
  280. isV6PluginInstall: false,
  281. isFileOpen: false,
  282. curPromise: {},
  283. checkInstall: function (argsobj, froceUpdate = false) {
  284. indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
  285. if (window.idxProcessCheck && !froceUpdate) {
  286. return window.idxProcessCheck
  287. }
  288. if (window.sessionStorage && sessionStorage.getItem('isV6PluginInstall') !== null) {
  289. indidocxobj.slCtl.isV6PluginInstall = JSON.parse(sessionStorage.getItem('isV6PluginInstall'))
  290. return Promise.resolve(indidocxobj.slCtl.isV6PluginInstall)
  291. }
  292. window.idxProcessCheck = indidocxobj.slCtl.Content.Control._initHttpServer(6000)
  293. return window.idxProcessCheck
  294. },
  295. getRef: function (str, start, substr, seperator) {
  296. var pos
  297. var endpos
  298. pos = str.indexOf(substr, start)
  299. if (pos == -1) return ''
  300. endpos = str.indexOf(seperator, pos + 1)
  301. if (endpos == -1) return str.substring(pos + substr.length, str.length)
  302. else return str.substring(pos + substr.length, endpos)
  303. },
  304. getFileType: function (strFileName) {
  305. var arrtmp = strFileName.split('.')
  306. return '.' + arrtmp.pop().toLowerCase()
  307. },
  308. htmldecode: function (s) {
  309. return s
  310. // var div = document.createElement('div')
  311. // div.innerHTML = s
  312. // return div.textContent
  313. },
  314. setFileList: function (data) {
  315. var strlist = new Array()
  316. for (var i = 0; i < data.length; i++) {
  317. strlist.push(
  318. data[i].properties +
  319. '<FileServerUrl>' +
  320. fnGetFileLink(data[i].code) +
  321. '</FileServerUrl>'
  322. )
  323. }
  324. if (strlist != null && strlist != undefined) {
  325. indidocxobj.slCtl.Content.Files._FileInfoString = strlist
  326. indidocxobj.slCtl.Content.Files.FileList = indidocxobj.slCtl.analyzeFileList() //解析filelist
  327. }
  328. },
  329. analyzeFileList: function () {
  330. var arrFileMap = indidocxobj.slCtl.Content.Files._FileInfoString.map(function (
  331. onefile,
  332. index
  333. ) {
  334. var filelink = ''
  335. if (typeof fnGetFileLink === 'function') {
  336. filelink = fnGetFileLink(
  337. indidocxobj.slCtl.getRef(onefile, 0, '<file_unid>', '</file_unid>')
  338. )
  339. }
  340. return {
  341. FileName: indidocxobj.slCtl.htmldecode(
  342. indidocxobj.slCtl.getRef(onefile, 0, '<file_name>', '</file_name>')
  343. ),
  344. Unid: indidocxobj.slCtl.getRef(onefile, 0, '<file_unid>', '</file_unid>'),
  345. CatNum: indidocxobj.slCtl.getRef(onefile, 0, '<CatNum>', '</CatNum>'),
  346. Size: indidocxobj.slCtl.getRef(onefile, 0, '<file_size>', '</file_size>'),
  347. FileType: indidocxobj.slCtl.getRef(onefile, 0, '<filetype>', '</filetype>'),
  348. Completed: parseInt(
  349. indidocxobj.slCtl.getRef(onefile, 0, '<completed>', '</completed>')
  350. ),
  351. doAdd:
  352. indidocxobj.slCtl.getRef(onefile, 0, '<doAdd>', '</doAdd>') == 'True'
  353. ? true
  354. : false,
  355. Type: indidocxobj.slCtl.getFileType(
  356. indidocxobj.slCtl.getRef(onefile, 0, '<file_name>', '</file_name>')
  357. ),
  358. CreateInfo: indidocxobj.slCtl.getRef(onefile, 0, '<CreateInfo>', '</CreateInfo>'),
  359. UpdateInfo: indidocxobj.slCtl.getRef(onefile, 0, '<UpdateInfo>', '</UpdateInfo>'),
  360. TaodaInfo: indidocxobj.slCtl.getRef(onefile, 0, '<TaodaInfo>', '</TaodaInfo>'),
  361. NeedUpdate: indidocxobj.slCtl.getRef(onefile, 0, '<NeedUpdate>', '</NeedUpdate>'),
  362. AllowPrint: false,
  363. DocUnid: indidocxobj.slCtl.getRef(onefile, 0, '<doc_unid>', '</doc_unid>'),
  364. Uploading:
  365. parseInt(indidocxobj.slCtl.getRef(onefile, 0, '<completed>', '</completed>')) ==
  366. 0 && indidocxobj.slCtl.getRef(onefile, 0, '<doAdd>', '</doAdd>') == 'False'
  367. ? true
  368. : false,
  369. Link: filelink,
  370. }
  371. })
  372. return arrFileMap
  373. },
  374. socketSend: function (url, opts) {
  375. if ('function' == typeof opts) {
  376. fn = opts
  377. opts = {}
  378. }
  379. if (!opts) opts = {}
  380. var prefix = opts.prefix || '__jp'
  381. // use the callback name that was passed if one was provided.
  382. // otherwise generate a unique name by incrementing our counter.
  383. var id = opts.name || prefix + this.count++
  384. var param = opts.param || 'callback'
  385. // add qs component
  386. var action = url.substr(url.lastIndexOf('/') + 1)
  387. action += (~action.indexOf('?') ? '&' : '?') + param + '=' + encodeURIComponent(id)
  388. action = action.replace('?&', '?')
  389. this.socketSendSafe(action, 5)
  390. },
  391. socketSendSafe(msg, times = 5) {
  392. if (times <= 0) {
  393. console.warn('通信中断')
  394. var start = msg.indexOf('callback') + 16
  395. var callback = msg.substr(start, msg.indexOf('&', start) - start)
  396. window[callback] && window[callback]({ Update: false })
  397. return
  398. }
  399. var curconn = window.IndidocxShareSocket || indidocxobj.slCtl.socket
  400. if (curconn.readyState == WebSocket.CONNECTING) {
  401. console.log('连接中')
  402. setTimeout(function () {
  403. indidocxobj.slCtl.socketSendSafe(msg, times - 1)
  404. }, 500)
  405. } else if (
  406. curconn.readyState == WebSocket.CLOSED ||
  407. curconn.readyState == WebSocket.CLOSING
  408. ) {
  409. curconn.open()
  410. console.log('重新启动socket')
  411. setTimeout(function () {
  412. indidocxobj.slCtl.socketSendSafe(msg, times - 1)
  413. }, 500)
  414. } else {
  415. //OPEN
  416. curconn.send(msg)
  417. }
  418. },
  419. receiveMsg: function (msg) {
  420. // console.log('get message ' + msg.data)
  421. eval(msg.data)
  422. },
  423. //控件传输层 V6控件发送请求 以后控件更换逻辑只需修改此函数即可
  424. sendRequest: function (action, contentJson, timeout, method) {
  425. contentJson.sid = indidocxobj.slCtl.id
  426. contentJson.Activation = indidocxobj.slCtl.Activation
  427. contentJson.base_host = location.origin
  428. contentJson.cookie = indidocxobj.slCtl.$$idx.httpserver.cookie
  429. contentJson.refresh_token = indidocxobj.slCtl.$$idx.httpserver.refresh_token
  430. contentJson.getActivationUrl = indidocxobj.slCtl.$$idx.httpserver.getActivationUrl
  431. contentJson.action = action
  432. contentJson.doTime = Date.now()
  433. var queryString = ''
  434. for (var key in contentJson) {
  435. queryString += key + '=' + encodeURIComponent(contentJson[key]) + '&'
  436. }
  437. indidocxobj.slCtl.socketSend(action, { param: queryString, timeout })
  438. },
  439. formatParams: function (argsobj) {
  440. var $$idxtemp = {}
  441. $$idxtemp.httpserver = {}
  442. $$idxtemp.httpserver.sid = argsobj.sid == undefined ? 'testuser' : argsobj.sid
  443. $$idxtemp.httpserver.Activation =
  444. argsobj.Activation == undefined ? '' : argsobj.Activation
  445. $$idxtemp.httpserver.UserName = argsobj.UserName == undefined ? 'admin' : argsobj.UserName
  446. $$idxtemp.httpserver.MaxFileSize =
  447. argsobj.MaxFileSize == undefined ? '20' : argsobj.MaxFileSize
  448. $$idxtemp.httpserver.SetTakeLogConfig =
  449. argsobj.SetTakeLogConfig == undefined ? 'true' : argsobj.SetTakeLogConfig
  450. $$idxtemp.httpserver.RefuseFileType =
  451. argsobj.RefuseFileType == undefined ? '' : argsobj.RefuseFileType
  452. $$idxtemp.httpserver.AcceptFileType =
  453. argsobj.AcceptFileType == undefined ? '' : argsobj.AcceptFileType
  454. $$idxtemp.httpserver.UseMark = argsobj.UseMark == undefined ? 'true' : argsobj.UseMark
  455. $$idxtemp.httpserver.ContentNeedFormate =
  456. argsobj.ContentNeedFormate == undefined ? '' : argsobj.ContentNeedFormate
  457. $$idxtemp.httpserver.TaoDaType = argsobj.TaoDaType == undefined ? '' : argsobj.TaoDaType
  458. $$idxtemp.httpserver.DirDeleteTime =
  459. argsobj.DirDeleteTime == undefined ? '' : argsobj.DirDeleteTime
  460. $$idxtemp.httpserver.FileFilter =
  461. argsobj.FileFilter == undefined ? '' : argsobj.FileFilter
  462. $$idxtemp.httpserver.MultiText = argsobj.MultiText == undefined ? '' : argsobj.MultiText
  463. $$idxtemp.httpserver.MaxAttachCount =
  464. argsobj.MaxAttachCount == undefined ? '' : argsobj.MaxAttachCount
  465. $$idxtemp.httpserver.UseRevise = argsobj.UseRevise == undefined ? '' : argsobj.UseRevise
  466. $$idxtemp.httpserver.UploadParam =
  467. argsobj.UploadParam == undefined ? '' : argsobj.UploadParam
  468. $$idxtemp.httpserver.UploadUrl = argsobj.UploadUrl == undefined ? '' : argsobj.UploadUrl
  469. $$idxtemp.httpserver.ServerUpdateUrl =
  470. argsobj.ServerUpdateUrl == undefined ? '' : argsobj.ServerUpdateUrl
  471. $$idxtemp.httpserver.cookie =
  472. argsobj.cookie == undefined ? '' : this.Base64.encode(argsobj.cookie)
  473. $$idxtemp.httpserver.refresh_token =
  474. argsobj.refresh_token == undefined ? '' : this.Base64.encode(argsobj.refresh_token)
  475. $$idxtemp.httpserver.getActivationUrl =
  476. argsobj.getActivationUrl == undefined ? '' : argsobj.getActivationUrl
  477. $$idxtemp.idxV6version = argsobj.idxV6version == undefined ? '' : argsobj.idxV6version
  478. indidocxobj.slCtl.id = $$idxtemp.httpserver.sid
  479. indidocxobj.slCtl.Activation = $$idxtemp.httpserver.Activation
  480. return $$idxtemp
  481. },
  482. // V6控件打开附件
  483. fnV6OpenFile: function (fname, fileparam) {
  484. indidocxobj.slCtl.isFileOpen = true
  485. var promise = new Promise((resolve, reject) => {
  486. let eventName = indidocxobj.slCtl.registerEvent('_OpenFileCompleted_', resolve, false)
  487. var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
  488. var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
  489. if (userfile == null) {
  490. userfile = {}
  491. ;(userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
  492. }
  493. var action = '/openfile'
  494. if (fileparam.NeedUpdate === undefined)
  495. fileparam.NeedUpdate = [1, 3, 2].indexOf(Number(fileparam.Status)) == -1
  496. var contentJson = {
  497. fileunid: userfile.Unid,
  498. fileinfo: usefileinfostring,
  499. fileparam: JSON.stringify(fileparam),
  500. UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
  501. UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
  502. UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
  503. callback: 'window.' + eventName,
  504. }
  505. var timeout = 0 // 60 * 5000
  506. indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
  507. }).catch(function (reason) {
  508. indidocxobj.slCtl.isFileOpen = false
  509. return Promise.reject(reason)
  510. })
  511. return promise
  512. },
  513. CreateTrackFileName: function (sourcename) {
  514. var count = 1
  515. var tmp = null
  516. var files = indidocxobj.slCtl.Content.Files
  517. for (var i = 0; i < files.FileList.length; i++) {
  518. var userFile = files.FileList[i]
  519. var filename = userFile.FileName
  520. if (filename.indexOf('痕迹稿') != -1 && filename.indexOf('_' + sourcename) != -1) {
  521. count++
  522. }
  523. }
  524. tmp = '痕迹稿' + count + '_' + sourcename //痕迹1_正文.doc
  525. return tmp
  526. },
  527. getV8IDXAddress: function () {
  528. if (window.location.protocol == 'http:') {
  529. return 'ws://' + indidocxobj.slCtl.domain + ':15880/indidocx'
  530. } else {
  531. return 'wss://' + indidocxobj.slCtl.domain + ':15881/indidocx'
  532. }
  533. },
  534. /**
  535. * 注册回调事件
  536. * @param {string} eventType 事件类型
  537. * @param {function} resolve
  538. * @param {boolean} isfileopen 标识打开文件
  539. * @returns {string} 事件名称
  540. */
  541. registerEvent(eventType, resolve, isfileopen) {
  542. let eventName = eventType + CreateRandomId() + '_' + indidocxobj.slCtl.forWindowID
  543. indidocxobj.slCtl.curPromise[eventName] = resolve
  544. window[eventName] = function (o) {
  545. if (isfileopen !== undefined) indidocxobj.slCtl.isFileOpen = isfileopen
  546. if (typeof fnRefreshFileList === 'function') {
  547. fnRefreshFileList()
  548. }
  549. if (o == undefined) {
  550. indidocxobj.slCtl.curPromise[eventName](false)
  551. return
  552. }
  553. //此处需要返回操作回调的参数
  554. indidocxobj.slCtl.curPromise[eventName](o)
  555. }
  556. return eventName
  557. },
  558. launchBrowser: function (url, type) {
  559. var action = '/launchie'
  560. var contentJson = {
  561. starturl: url,
  562. browser: type,
  563. }
  564. this.sendRequest(action, contentJson)
  565. },
  566. Content: {
  567. Files: {
  568. FileList: [],
  569. _FileInfoString: [],
  570. FileUploadDoing: function () {},
  571. AllFilePost: function () {},
  572. ErrorOccurred: function () {},
  573. SingleFileUploadFinished: function () {},
  574. FileDeleted: function () {},
  575. DupNameFile: function () {},
  576. _anylaze: function () {},
  577. _syncFileInfo: function () {},
  578. },
  579. Control: {
  580. ReadHTML: function () {},
  581. getHTMLed: function () {},
  582. getLablesed: function () {},
  583. FileConvertPDFed: function () {},
  584. FileAdded: function () {},
  585. ActionEnd: function () {},
  586. EventRegioned: function () {},
  587. SingleFileDownloaded: function () {},
  588. SilentDownloaded: function () {},
  589. ErrorMessage: function () {},
  590. OnFileSelected: function () {},
  591. getPrintListed: function () {},
  592. SaveFileCompleted: function () {},
  593. _getversionCompleted: function (o) {
  594. console.log(o.message)
  595. },
  596. _getFileStatued: function () {},
  597. _inithttpCompleted: function () {},
  598. _initHttpServer: function (timeout, tresolve, treject) {
  599. var promise = new Promise((resolve, reject) => {
  600. let eventName = '_inithttpCompleted_' + indidocxobj.slCtl.forWindowID
  601. window[eventName] = function (o) {
  602. var returnValue = false
  603. if (indidocxobj.slCtl.isV6PluginInstall != false) {
  604. //已经初始化成功
  605. returnValue = indidocxobj.slCtl.isV6PluginInstall
  606. resolve(returnValue)
  607. tresolve && tresolve(returnValue)
  608. return
  609. }
  610. if (o == undefined) {
  611. //伪成功事件
  612. indidocxobj.slCtl.isV6PluginInstall = false
  613. returnValue = indidocxobj.slCtl.isV6PluginInstall
  614. return
  615. }
  616. if (o.Update != '' && o.querystring != undefined) {
  617. indidocxobj.slCtl.isV6PluginInstall = o
  618. //this.Content.Control._synMessage();
  619. returnValue = o
  620. if (window.sessionStorage) {
  621. sessionStorage.setItem('isV6PluginInstall', JSON.stringify(o))
  622. }
  623. if (o.querystring.indexOf('授权') > -1) {
  624. returnValue = o.querystring
  625. }
  626. if (!!indidocxobj.slCtl.uploadCompentInfoUrl)
  627. indidocxobj.slCtl.Content.Control._uploadCompentInfo(o)
  628. }
  629. resolve(returnValue) //是否安装控件
  630. tresolve && tresolve(returnValue)
  631. }
  632. var baseUrl = '/inithttpserver'
  633. var contentJson = {
  634. idxversion: indidocxobj.slCtl.$$idx.idxV6version,
  635. ServerUpdateUrl: indidocxobj.slCtl.$$idx.httpserver.ServerUpdateUrl,
  636. UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
  637. UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
  638. UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
  639. callback: 'window.' + eventName,
  640. }
  641. indidocxobj.slCtl.sendRequest(baseUrl, contentJson, 30000, 'get')
  642. if (timeout == undefined) {
  643. timeout = 8000
  644. }
  645. setTimeout(window[eventName], timeout)
  646. }).catch(function (reason) {
  647. return Promise.reject(reason)
  648. })
  649. return promise
  650. },
  651. _uploadCompentInfo: function (serverinfo) {
  652. var state = JSON.parse(sessionStorage.getItem('vuex'))
  653. var userinfo = state?.sd?.common?.userInfo?.default || {}
  654. var data = {
  655. userId: userinfo.id,
  656. userAccount: userinfo.account,
  657. userName: userinfo.name,
  658. updateDate: Date.now(), //当前日期的毫秒值
  659. controlType: 'IndidocX',
  660. // browsername: navigator.userAgent,
  661. equipmentName: serverinfo.HostName,
  662. indidocxVersion: serverinfo.Update, //inididoc版本
  663. }
  664. var ajax = indidocxobj.slCtl.createXHR()
  665. ajax.open('POST', indidocxobj.slCtl.uploadCompentInfoUrl)
  666. ajax.onreadystatechange = function () {
  667. if (ajax.readyState == 4 && ajax.status == 200) {
  668. console.log('上传组件信息成功')
  669. }
  670. }
  671. ajax.setRequestHeader('Cache-Control', 'no-cache')
  672. ajax.setRequestHeader('Content-type', 'application/json;charset=utf-8')
  673. ajax.setRequestHeader('Authorization', state?.sd?.login?.tokens?.access_token)
  674. ajax.send(JSON.stringify(data))
  675. },
  676. _getServerMessage: function (o) {
  677. if (typeof handleIdxMessage === 'function') {
  678. handleIdxMessage(o)
  679. }
  680. indidocxobj.slCtl.Content.Control._synMessage()
  681. },
  682. _synMessage: function () {
  683. let eventName = '_getServerMessage_' + indidocxobj.slCtl.forWindowID
  684. var baseUrl = '/synmessage'
  685. var contentJson = {
  686. sid: indidocxobj.slCtl.id,
  687. callback: 'window.' + eventName,
  688. }
  689. indidocxobj.slCtl.sendRequest(baseUrl, contentJson, 3000000, 'get')
  690. },
  691. _getVersion: function () {
  692. let eventName = '_getversionCompleted_' + indidocxobj.slCtl.forWindowID
  693. var baseUrl = '/getversion'
  694. var contentJson = {
  695. sid: indidocxobj.slCtl.id,
  696. callback: 'window.' + eventName,
  697. }
  698. indidocxobj.slCtl.sendRequest(baseUrl, contentJson, 30000, 'get')
  699. },
  700. _getTerminalInfo: function () {
  701. let eventName = '_geTerminalInfoCompleted_' + indidocxobj.slCtl.forWindowID
  702. var baseUrl = '/getterminalinfo'
  703. var contentJson = {
  704. sid: indidocxobj.slCtl.id,
  705. callback: 'window.' + eventName,
  706. }
  707. indidocxobj.slCtl.sendRequest(baseUrl, contentJson, 30000, 'get')
  708. },
  709. getFileByName: function (fname) {
  710. var userfile = null
  711. indidocxobj.slCtl.Content.Files.FileList.map(function (onefile, index) {
  712. if (onefile.Unid == fname || onefile.FileName == fname) {
  713. userfile = onefile
  714. }
  715. })
  716. return userfile
  717. },
  718. _getFileInfoByName: function (fname) {
  719. var usefileinfostring = null
  720. indidocxobj.slCtl.Content.Files._FileInfoString.map(function (onefile, index) {
  721. if (
  722. indidocxobj.slCtl.getRef(onefile, 0, '<file_unid>', '</file_unid>') == fname ||
  723. indidocxobj.slCtl.htmldecode(
  724. indidocxobj.slCtl.getRef(onefile, 0, '<file_name>', '</file_name>')
  725. ) == fname
  726. ) {
  727. usefileinfostring = onefile
  728. }
  729. })
  730. return usefileinfostring
  731. },
  732. //编辑
  733. EditFile: function (fname, fileparam, argsobj) {
  734. indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
  735. return indidocxobj.slCtl.fnV6OpenFile(fname, fileparam)
  736. },
  737. //打开本地文件夹
  738. OpenLoaclDir: function (openpath, argsobj) {
  739. var promise = new Promise((resolve, reject) => {
  740. let eventName = indidocxobj.slCtl.registerEvent('_OpenLoaclDirCompleted_', resolve)
  741. indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
  742. var action = '/openloacldir'
  743. var contentJson = {
  744. openfiledir: openpath,
  745. callback: 'window.' + eventName,
  746. }
  747. var timeout = 60 * 5000
  748. indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
  749. }).catch(function (reason) {
  750. return Promise.reject(reason)
  751. })
  752. return promise
  753. },
  754. //下载附件
  755. SaveFileToLocal: function (fname, fileparam, argsobj) {
  756. var promise = new Promise((resolve, reject) => {
  757. let eventName = indidocxobj.slCtl.registerEvent('_SaveFileCompleted_', resolve)
  758. indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
  759. var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
  760. var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
  761. if (userfile == null) {
  762. userfile = {}
  763. ;(userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
  764. }
  765. var action = '/downloadfile'
  766. if (fileparam == undefined) fileparam = ''
  767. var contentJson = {
  768. fileunid: userfile.Unid,
  769. fileparam: JSON.stringify(fileparam),
  770. fileinfo: usefileinfostring,
  771. callback: 'window.' + eventName,
  772. }
  773. var timeout = 60 * 5000
  774. indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
  775. }).catch(function (reason) {
  776. return Promise.reject(reason)
  777. })
  778. return promise
  779. },
  780. //批量下载
  781. SaveMultiFiles: function (strFiles, fileparam, argsobj) {
  782. var promise = new Promise((resolve, reject) => {
  783. let eventName = indidocxobj.slCtl.registerEvent('_SaveFileCompleted_', resolve)
  784. indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
  785. if (fileparam == undefined) fileparam = ''
  786. var arrFileNames = strFiles.split('|')
  787. var strFilesInfo = ''
  788. for (var j = 0, len = arrFileNames.length; j < len; j++) {
  789. if (arrFileNames[j] != '') {
  790. for (
  791. var i = 0, ten = indidocxobj.slCtl.Content.Files.FileList.length;
  792. i < ten;
  793. i++
  794. ) {
  795. if (arrFileNames[j] == indidocxobj.slCtl.Content.Files.FileList[i].FileName) {
  796. if (
  797. indidocxobj.slCtl.Content.Files.FileList[i].Link.indexOf('fileName') > 0
  798. ) {
  799. strFilesInfo += '|' + indidocxobj.slCtl.Content.Files.FileList[i].Link
  800. } else {
  801. strFilesInfo +=
  802. '|' +
  803. indidocxobj.slCtl.Content.Files.FileList[i].Link +
  804. '?fileName=' +
  805. arrFileNames[j]
  806. }
  807. }
  808. }
  809. }
  810. }
  811. var action = '/downloadmultifile'
  812. var contentJson = {
  813. fileparam: JSON.stringify(fileparam),
  814. files: strFilesInfo,
  815. callback: 'window.' + eventName,
  816. }
  817. var timeout = 60 * 5000
  818. indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
  819. }).catch(function (reason) {
  820. return Promise.reject(reason)
  821. })
  822. return promise
  823. },
  824. //清稿
  825. QingGao: function (fname, fileparam, argsobj) {
  826. indidocxobj.slCtl.isFileOpen = true
  827. var promise = new Promise((resolve, reject) => {
  828. let eventName = indidocxobj.slCtl.registerEvent(
  829. '_OpenFileCompleted_',
  830. resolve,
  831. false
  832. )
  833. indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
  834. var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
  835. var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
  836. if (userfile == null) {
  837. userfile = {}
  838. ;(userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
  839. }
  840. var _files = ''
  841. for (
  842. var j = 0, len = indidocxobj.slCtl.Content.Files.FileList.length;
  843. j < len;
  844. j++
  845. ) {
  846. _files += '|' + indidocxobj.slCtl.Content.Files.FileList[j].FileName
  847. }
  848. var action = '/qinggao'
  849. var contentJson = {
  850. fileunid: userfile.Unid,
  851. fileinfo: usefileinfostring,
  852. fileparam: JSON.stringify(fileparam),
  853. UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
  854. UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
  855. UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
  856. trackFileName: indidocxobj.slCtl.CreateTrackFileName(fname),
  857. callback: 'window.' + eventName,
  858. }
  859. var timeout = 0 //60 * 2000
  860. indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
  861. }).catch(function (reason) {
  862. indidocxobj.slCtl.isFileOpen = false
  863. return Promise.reject(reason)
  864. })
  865. return promise
  866. },
  867. //套打
  868. TaoDa: function (
  869. ModelUrl,
  870. ContentFieldName,
  871. fname,
  872. fileparam,
  873. OldDocName,
  874. values,
  875. taodainfo,
  876. argsobj
  877. ) {
  878. var replacename = ''
  879. if (checkFileExt(ModelUrl, '.docx')) {
  880. replacename = CreateRandomId() + '.docx'
  881. } else if (checkFileExt(ModelUrl, '.doc')) {
  882. replacename = CreateRandomId() + '.doc'
  883. }
  884. ModelUrl = changeURLArg(ModelUrl, 'fileName', replacename)
  885. indidocxobj.slCtl.isFileOpen = true
  886. var promise = new Promise((resolve, reject) => {
  887. let eventName = indidocxobj.slCtl.registerEvent(
  888. '_OpenFileCompleted_',
  889. resolve,
  890. false
  891. )
  892. indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
  893. var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
  894. var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
  895. if (userfile == null) {
  896. userfile = {}
  897. ;(userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
  898. } else {
  899. var infoarr = usefileinfostring.split('<TaodaInfo>')
  900. usefileinfostring =
  901. infoarr[0] +
  902. '<TaodaInfo>' +
  903. taodainfo +
  904. '</TaodaInfo>' +
  905. infoarr[1].split('</TaodaInfo>')[1]
  906. //更新taodainfo
  907. for (var i = 0; i < indidocxobj.slCtl.Content.Files._FileInfoString.length; i++) {
  908. if (
  909. indidocxobj.slCtl.getRef(
  910. indidocxobj.slCtl.Content.Files._FileInfoString[i],
  911. 0,
  912. '<file_unid>',
  913. '</file_unid>'
  914. ) == fname ||
  915. indidocxobj.slCtl.getRef(
  916. indidocxobj.slCtl.Content.Files._FileInfoString[i],
  917. 0,
  918. '<file_name>',
  919. '</file_name>'
  920. ) == fname
  921. ) {
  922. indidocxobj.slCtl.Content.Files._FileInfoString.splice(
  923. i,
  924. 1,
  925. usefileinfostring
  926. )
  927. }
  928. }
  929. }
  930. var _files = ''
  931. for (
  932. var j = 0, len = indidocxobj.slCtl.Content.Files.FileList.length;
  933. j < len;
  934. j++
  935. ) {
  936. _files += '|' + indidocxobj.slCtl.Content.Files.FileList[j].FileName
  937. }
  938. var action = '/taoda'
  939. var contentJson = {
  940. fileunid: userfile.Unid,
  941. olddocname: OldDocName,
  942. model_url: ModelUrl,
  943. contentfieldname: ContentFieldName,
  944. fieldvalues: JSON.stringify(values),
  945. fileparam: JSON.stringify(fileparam),
  946. fileinfo: usefileinfostring,
  947. UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
  948. UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
  949. UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
  950. callback: 'window.' + eventName,
  951. }
  952. var timeout = 0 // 60 * 2000
  953. indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
  954. }).catch(function (reason) {
  955. indidocxobj.slCtl.isFileOpen = false
  956. return Promise.reject(reason)
  957. })
  958. return promise
  959. },
  960. //盖章
  961. GaiZhang: function (
  962. ModelUrl,
  963. ContentFieldName,
  964. fname,
  965. fileparam,
  966. OldDocName,
  967. values,
  968. argsobj
  969. ) {
  970. var replacename = ''
  971. if (checkFileExt(ModelUrl, '.docx')) {
  972. replacename = CreateRandomId() + '.docx'
  973. } else if (checkFileExt(ModelUrl, '.doc')) {
  974. replacename = CreateRandomId() + '.doc'
  975. }
  976. ModelUrl = changeURLArg(ModelUrl, 'fileName', replacename)
  977. indidocxobj.slCtl.isFileOpen = true
  978. var promise = new Promise((resolve, reject) => {
  979. let eventName = indidocxobj.slCtl.registerEvent(
  980. '_OpenFileCompleted_',
  981. resolve,
  982. false
  983. )
  984. indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
  985. var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
  986. var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
  987. if (userfile == null) {
  988. userfile = {}
  989. ;(userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
  990. }
  991. var action = '/gaizhang'
  992. var contentJson = {
  993. fileunid: userfile.Unid,
  994. model_url: ModelUrl,
  995. contentfieldname: ContentFieldName,
  996. fileparam: JSON.stringify(fileparam),
  997. fieldvalues: JSON.stringify(values),
  998. fileinfo: usefileinfostring,
  999. UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
  1000. UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
  1001. UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
  1002. callback: 'window.' + eventName,
  1003. }
  1004. var timeout = 0 // 60 * 2000
  1005. indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
  1006. }).catch(function (reason) {
  1007. indidocxobj.slCtl.isFileOpen = false
  1008. return Promise.reject(reason)
  1009. })
  1010. return promise
  1011. },
  1012. //更新正文
  1013. UpdateRegion: function (fname, values, picvalues, fileparam, argsobj) {
  1014. indidocxobj.slCtl.isFileOpen = true
  1015. var promise = new Promise((resolve, reject) => {
  1016. let eventName = indidocxobj.slCtl.registerEvent(
  1017. '_OpenFileCompleted_',
  1018. resolve,
  1019. false
  1020. )
  1021. indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
  1022. var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
  1023. var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
  1024. if (userfile == null) {
  1025. userfile = {}
  1026. ;(userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
  1027. }
  1028. var action = '/updateregion'
  1029. var contentJson = {
  1030. fieldvalues: JSON.stringify(values),
  1031. picvalues: picvalues,
  1032. fileunid: userfile.Unid,
  1033. fileparam: JSON.stringify(fileparam),
  1034. fileinfo: usefileinfostring,
  1035. UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
  1036. UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
  1037. UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
  1038. callback: 'window.' + eventName,
  1039. }
  1040. var timeout = 0 // 60 * 2000
  1041. indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
  1042. }).catch(function (reason) {
  1043. indidocxobj.slCtl.isFileOpen = false
  1044. return Promise.reject(reason)
  1045. })
  1046. return promise
  1047. },
  1048. //文档打印
  1049. PrintDocument: function (fname, fileparam, values, argsobj) {
  1050. var promise = new Promise((resolve, reject) => {
  1051. let eventName = indidocxobj.slCtl.registerEvent('_OpenFileCompleted_', resolve)
  1052. indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
  1053. var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
  1054. var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
  1055. if (userfile == null) {
  1056. userfile = {}
  1057. ;(userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
  1058. }
  1059. var action = '/printdocument'
  1060. var contentJson = {
  1061. fieldvalues: JSON.stringify(values),
  1062. fileunid: userfile.Unid,
  1063. fileparam: JSON.stringify(fileparam),
  1064. fileinfo: usefileinfostring,
  1065. UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
  1066. UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
  1067. UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
  1068. callback: 'window.' + eventName,
  1069. }
  1070. var timeout = 0 // 60 * 2000
  1071. indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
  1072. }).catch(function (reason) {
  1073. return Promise.reject(reason)
  1074. })
  1075. return promise
  1076. },
  1077. //转换pdf
  1078. DOCConvertToPDF: function (fname, fileparam, argsobj) {
  1079. indidocxobj.slCtl.isFileOpen = true
  1080. var promise = new Promise((resolve, reject) => {
  1081. let eventName = indidocxobj.slCtl.registerEvent('_OpenFileCompleted_', resolve)
  1082. indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
  1083. var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
  1084. var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
  1085. if (userfile == null) {
  1086. userfile = {}
  1087. ;(userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
  1088. }
  1089. var action = '/convertdoctopdf'
  1090. var contentJson = {
  1091. fileunid: userfile.Unid,
  1092. fileinfo: usefileinfostring,
  1093. UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
  1094. UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
  1095. UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
  1096. callback: 'window.' + eventName,
  1097. }
  1098. var timeout = 0 // 60 * 5000
  1099. indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
  1100. }).catch(function (reason) {
  1101. indidocxobj.slCtl.isFileOpen = false
  1102. return Promise.reject(reason)
  1103. })
  1104. return promise
  1105. },
  1106. DOCConvertToOFD: function (fname, fileparam, argsobj) {
  1107. var promise = new Promise((resolve, reject) => {
  1108. let eventName = indidocxobj.slCtl.registerEvent('_OpenFileCompleted_', resolve)
  1109. indidocxobj.slCtl.$$idx = indidocxobj.slCtl.formatParams(argsobj)
  1110. var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
  1111. var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
  1112. if (userfile == null) {
  1113. userfile = {}
  1114. ;(userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
  1115. }
  1116. var action = '/convertdoctoofd'
  1117. var contentJson = {
  1118. fileunid: userfile.Unid,
  1119. fileinfo: usefileinfostring,
  1120. UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
  1121. UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
  1122. UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
  1123. callback: 'window.' + eventName,
  1124. }
  1125. var timeout = 0 //60 * 5000
  1126. indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
  1127. }).catch(function (reason) {
  1128. return Promise.reject(reason)
  1129. })
  1130. return promise
  1131. },
  1132. //图片章
  1133. TuPianZhang: function (fname, fileparam, argsobj) {
  1134. var promise = new Promise((resolve, reject) => {
  1135. let eventName = indidocxobj.slCtl.registerEvent('_TuPianZhangCompleted_', resolve, false)
  1136. var userfile = indidocxobj.slCtl.Content.Control.getFileByName(fname)
  1137. var usefileinfostring = indidocxobj.slCtl.Content.Control._getFileInfoByName(fname)
  1138. if (userfile == null) {
  1139. userfile = {}
  1140. ; (userfile.Unid = CreateRandomId()), (usefileinfostring = fname)
  1141. }
  1142. var action = '/tupianzhang'
  1143. var contentJson = {
  1144. fileunid: userfile.Unid,
  1145. fileinfo: usefileinfostring,
  1146. fileparam: JSON.stringify(fileparam),
  1147. UserName: indidocxobj.slCtl.$$idx.httpserver.UserName,
  1148. UploadParam: indidocxobj.slCtl.$$idx.httpserver.UploadParam,
  1149. UploadUrl: indidocxobj.slCtl.$$idx.httpserver.UploadUrl,
  1150. callback: 'window.' + eventName,
  1151. }
  1152. var timeout = 0 // 60 * 5000
  1153. indidocxobj.slCtl.sendRequest(action, contentJson, timeout, 'get')
  1154. }).catch(function (reason) {
  1155. return Promise.reject(reason)
  1156. })
  1157. return promise
  1158. },
  1159. },
  1160. },
  1161. createXHR: function () {
  1162. if (typeof XMLHttpRequest != 'undefined') {
  1163. //兼容高版本浏览器
  1164. return new XMLHttpRequest()
  1165. } else if (typeof ActiveXObject != 'undefined') {
  1166. //IE6 采用 ActiveXObject, 兼容IE6
  1167. var versions = [
  1168. //由于MSXML库有3个版本,因此都要考虑
  1169. 'MSXML2.XMLHttp.6.0',
  1170. 'MSXML2.XMLHttp.3.0',
  1171. 'MSXML2.XMLHttp',
  1172. ]
  1173. for (var i = 0; i < versions.length; i++) {
  1174. try {
  1175. return new ActiveXObject(versions[i])
  1176. } catch (e) {
  1177. //跳过
  1178. }
  1179. }
  1180. } else {
  1181. throw new Error('您的浏览器不支持XHR对象')
  1182. }
  1183. },
  1184. Base64: {
  1185. base64EncodeChars: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
  1186. base64DecodeChars: new Array(
  1187. -1,
  1188. -1,
  1189. -1,
  1190. -1,
  1191. -1,
  1192. -1,
  1193. -1,
  1194. -1,
  1195. -1,
  1196. -1,
  1197. -1,
  1198. -1,
  1199. -1,
  1200. -1,
  1201. -1,
  1202. -1,
  1203. -1,
  1204. -1,
  1205. -1,
  1206. -1,
  1207. -1,
  1208. -1,
  1209. -1,
  1210. -1,
  1211. -1,
  1212. -1,
  1213. -1,
  1214. -1,
  1215. -1,
  1216. -1,
  1217. -1,
  1218. -1,
  1219. -1,
  1220. -1,
  1221. -1,
  1222. -1,
  1223. -1,
  1224. -1,
  1225. -1,
  1226. -1,
  1227. -1,
  1228. -1,
  1229. -1,
  1230. 62,
  1231. -1,
  1232. -1,
  1233. -1,
  1234. 63,
  1235. 52,
  1236. 53,
  1237. 54,
  1238. 55,
  1239. 56,
  1240. 57,
  1241. 58,
  1242. 59,
  1243. 60,
  1244. 61,
  1245. -1,
  1246. -1,
  1247. -1,
  1248. -1,
  1249. -1,
  1250. -1,
  1251. -1,
  1252. 0,
  1253. 1,
  1254. 2,
  1255. 3,
  1256. 4,
  1257. 5,
  1258. 6,
  1259. 7,
  1260. 8,
  1261. 9,
  1262. 10,
  1263. 11,
  1264. 12,
  1265. 13,
  1266. 14,
  1267. 15,
  1268. 16,
  1269. 17,
  1270. 18,
  1271. 19,
  1272. 20,
  1273. 21,
  1274. 22,
  1275. 23,
  1276. 24,
  1277. 25,
  1278. -1,
  1279. -1,
  1280. -1,
  1281. -1,
  1282. -1,
  1283. -1,
  1284. 26,
  1285. 27,
  1286. 28,
  1287. 29,
  1288. 30,
  1289. 31,
  1290. 32,
  1291. 33,
  1292. 34,
  1293. 35,
  1294. 36,
  1295. 37,
  1296. 38,
  1297. 39,
  1298. 40,
  1299. 41,
  1300. 42,
  1301. 43,
  1302. 44,
  1303. 45,
  1304. 46,
  1305. 47,
  1306. 48,
  1307. 49,
  1308. 50,
  1309. 51,
  1310. -1,
  1311. -1,
  1312. -1,
  1313. -1,
  1314. -1
  1315. ),
  1316. base64encode: function (str) {
  1317. var out, i, len
  1318. var c1, c2, c3
  1319. len = str.length
  1320. i = 0
  1321. out = ''
  1322. while (i < len) {
  1323. c1 = str.charCodeAt(i++) & 0xff
  1324. if (i == len) {
  1325. out += this.base64EncodeChars.charAt(c1 >> 2)
  1326. out += this.base64EncodeChars.charAt((c1 & 0x3) << 4)
  1327. out += '=='
  1328. break
  1329. }
  1330. c2 = str.charCodeAt(i++)
  1331. if (i == len) {
  1332. out += this.base64EncodeChars.charAt(c1 >> 2)
  1333. out += this.base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4))
  1334. out += this.base64EncodeChars.charAt((c2 & 0xf) << 2)
  1335. out += '='
  1336. break
  1337. }
  1338. c3 = str.charCodeAt(i++)
  1339. out += this.base64EncodeChars.charAt(c1 >> 2)
  1340. out += this.base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4))
  1341. out += this.base64EncodeChars.charAt(((c2 & 0xf) << 2) | ((c3 & 0xc0) >> 6))
  1342. out += this.base64EncodeChars.charAt(c3 & 0x3f)
  1343. }
  1344. return out
  1345. },
  1346. base64decode: function (str) {
  1347. var c1, c2, c3, c4
  1348. var i, len, out
  1349. len = str.length
  1350. i = 0
  1351. out = ''
  1352. while (i < len) {
  1353. do {
  1354. c1 = this.base64DecodeChars[str.charCodeAt(i++) & 0xff]
  1355. } while (i < len && c1 == -1)
  1356. if (c1 == -1) break
  1357. do {
  1358. c2 = this.base64DecodeChars[str.charCodeAt(i++) & 0xff]
  1359. } while (i < len && c2 == -1)
  1360. if (c2 == -1) break
  1361. out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4))
  1362. do {
  1363. c3 = str.charCodeAt(i++) & 0xff
  1364. if (c3 == 61) return out
  1365. c3 = this.base64DecodeChars[c3]
  1366. } while (i < len && c3 == -1)
  1367. if (c3 == -1) break
  1368. out += String.fromCharCode(((c2 & 0xf) << 4) | ((c3 & 0x3c) >> 2))
  1369. do {
  1370. c4 = str.charCodeAt(i++) & 0xff
  1371. if (c4 == 61) return out
  1372. c4 = this.base64DecodeChars[c4]
  1373. } while (i < len && c4 == -1)
  1374. if (c4 == -1) break
  1375. out += String.fromCharCode(((c3 & 0x03) << 6) | c4)
  1376. }
  1377. return out
  1378. },
  1379. utf16to8: function (str) {
  1380. var out, i, len, c
  1381. out = ''
  1382. len = str.length
  1383. for (i = 0; i < len; i++) {
  1384. c = str.charCodeAt(i)
  1385. if (c >= 0x0001 && c <= 0x007f) {
  1386. out += str.charAt(i)
  1387. } else if (c > 0x07ff) {
  1388. out += String.fromCharCode(0xe0 | ((c >> 12) & 0x0f))
  1389. out += String.fromCharCode(0x80 | ((c >> 6) & 0x3f))
  1390. out += String.fromCharCode(0x80 | ((c >> 0) & 0x3f))
  1391. } else {
  1392. out += String.fromCharCode(0xc0 | ((c >> 6) & 0x1f))
  1393. out += String.fromCharCode(0x80 | ((c >> 0) & 0x3f))
  1394. }
  1395. }
  1396. return out
  1397. },
  1398. utf8to16: function (str) {
  1399. var out, i, len, c
  1400. var char2, char3
  1401. out = ''
  1402. len = str.length
  1403. i = 0
  1404. while (i < len) {
  1405. c = str.charCodeAt(i++)
  1406. switch (c >> 4) {
  1407. case 0:
  1408. case 1:
  1409. case 2:
  1410. case 3:
  1411. case 4:
  1412. case 5:
  1413. case 6:
  1414. case 7:
  1415. // 0xxxxxxx
  1416. out += str.charAt(i - 1)
  1417. break
  1418. case 12:
  1419. case 13:
  1420. // 110x xxxx 10xx xxxx
  1421. char2 = str.charCodeAt(i++)
  1422. out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f))
  1423. break
  1424. case 14:
  1425. // 1110 xxxx 10xx xxxx 10xx xxxx
  1426. char2 = str.charCodeAt(i++)
  1427. char3 = str.charCodeAt(i++)
  1428. out += String.fromCharCode(
  1429. ((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0)
  1430. )
  1431. break
  1432. }
  1433. }
  1434. return out
  1435. }, //end
  1436. encode: function (input) {
  1437. return this.base64encode(this.utf16to8(input))
  1438. },
  1439. decode: function (str) {
  1440. return this.utf8to16(this.base64decode(str))
  1441. },
  1442. },
  1443. },
  1444. }
  1445. /**
  1446. * 获取随机ID
  1447. * @returns string
  1448. */
  1449. function CreateRandomId() {
  1450. return Number(Math.random().toString().substr(3, 3) + Date.now()).toString(36)
  1451. }
  1452. /**
  1453. * 修改url参数
  1454. */
  1455. function changeURLArg(url, arg, arg_val) {
  1456. var pattern = arg + '=([^&]*)'
  1457. var replaceText = arg + '=' + arg_val
  1458. if (url.match(pattern)) {
  1459. var tmp = '/(' + arg + '=)([^&]*)/gi'
  1460. tmp = url.replace(eval(tmp), replaceText)
  1461. return tmp
  1462. } else {
  1463. if (url.match('[?]')) {
  1464. return url + '&' + replaceText
  1465. } else {
  1466. return url + '?' + replaceText
  1467. }
  1468. }
  1469. }
  1470. /**
  1471. * 判断后缀
  1472. */
  1473. function checkFileExt(filename, ext) {
  1474. var index = filename.lastIndexOf('.')
  1475. filename = filename.substring(index)
  1476. if (filename.toLowerCase() == ext) {
  1477. return true
  1478. } else {
  1479. return false
  1480. }
  1481. }
  1482. if (!window.slCtlList) {
  1483. window.slCtlList = []
  1484. }
  1485. window.slCtlList.push(indidocxobj)
  1486. //初始化socket
  1487. var conn = window.IndidocxShareSocket || indidocxobj.slCtl.socket
  1488. if (conn == undefined) {
  1489. conn = new ReconnectingWebSocket(indidocxobj.slCtl.getV8IDXAddress())
  1490. conn.onmessage = indidocxobj.slCtl.receiveMsg
  1491. window.IndidocxShareSocket = conn
  1492. indidocxobj.slCtl.socket = conn
  1493. }
  1494. return indidocxobj
  1495. },
  1496. }
  1497. export default indidocxModule