index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. * @Author: Yolo
  3. * @Last Modified by: Yolo
  4. * @Last Modified time: 2020-09-03 17:26:35
  5. * @Last Modified time: 2020-10-28 15:01:45
  6. */
  7. <template>
  8. <div class="schedule"
  9. v-if="isShowSchedule">
  10. <div class="img"></div>
  11. <div class="info"
  12. v-if="isShowInfo">
  13. <p> {{ info.title }} </p>
  14. <div class="info__footer">
  15. <el-button icon="iconfont iconchushihua"
  16. @click="btnClick">
  17. {{ info.btnText }}
  18. </el-button>
  19. </div>
  20. </div>
  21. <div class="progress"
  22. v-if="!isShowInfo">
  23. <span>
  24. {{ getMessage }}
  25. </span>
  26. <div class="progress——bar"
  27. v-if="isProgress">
  28. <el-progress :percentage="progress.percentage"
  29. :stroke-width="8"
  30. :format="format"
  31. :color="progress.color"></el-progress>
  32. <span :class="progress.errorMsg ? 'errorMsg' : 'msg'">
  33. {{ progress.errorMsg ? progress.errorMsg : progress.msg }}
  34. </span>
  35. </div>
  36. <div class="progress——loadding">
  37. <img src="./image/loading2.gif"
  38. v-if="isShowLoadding" />
  39. </div>
  40. </div>
  41. </div>
  42. </template>
  43. <script>
  44. import { EventBus, fmoney } from 'base-core-lib'
  45. import {
  46. getProgressPercentage,
  47. getInitDb,
  48. getIsShowDialog
  49. } from '@/model/indexRx'
  50. import { mapActions } from 'vuex'
  51. export default {
  52. name: 'ShipboardInitializationSchedule',
  53. props: {},
  54. data () {
  55. return {
  56. isShowSchedule: false,
  57. isShowInfo: true,
  58. isProgress: false,
  59. isShowLoadding: false,
  60. interval: '',
  61. reStart: '',
  62. info: {
  63. title:
  64. '已经完成安装船舶管理系统客户端请您点击下方按钮系统将为您准备初始化数据',
  65. btnText: '数据初始化'
  66. },
  67. progress: {
  68. initTip: '正在进行数据初始化...',
  69. percentage: 0,
  70. successTip: '数据初始化完成,正在启动服务,请稍后...',
  71. errorTip: '数据初始化失败,请联系赢海客服0411-66895548',
  72. errorMsg: '',
  73. color: '#409eff',
  74. msg: ''
  75. }
  76. }
  77. },
  78. computed: {
  79. /**
  80. * 获取提示信息
  81. */
  82. getMessage () {
  83. return this.progress.percentage < 100
  84. ? this.progress.errorMsg
  85. ? this.progress.errorTip
  86. : this.progress.initTip
  87. : this.progress.successTip
  88. }
  89. },
  90. async created () {
  91. this.interval ? clearInterval(this.interval) : ''
  92. this.init()
  93. },
  94. methods: {
  95. ...mapActions('user', ['setScheduleState']),
  96. /**
  97. * 初始化数据
  98. * @param type wait 等待重启完成 不传递为判断是否弹出相应的框体
  99. * @Event on-schedul 传递弹出窗体事件
  100. */
  101. async init (type) {
  102. let { status, vesselName = '', code } = await getIsShowDialog().toPromise()
  103. if (code * 1 === 200) {
  104. if (!type) {
  105. this.isShowSchedule = status
  106. this.info.title = `${vesselName}${this.info.title}`
  107. this.$emit('on-schedule', status)
  108. this.setScheduleState(status)
  109. if (!status) {
  110. this.$emit('on-restart', true)
  111. }
  112. } else {
  113. this.isShowSchedule = false
  114. this.setScheduleState(false)
  115. this.$emit('on-restart', true)
  116. this.reStart ? clearInterval(this.reStart) : ''
  117. }
  118. }
  119. },
  120. /**
  121. * 按钮点击事件
  122. */
  123. async btnClick () {
  124. let {
  125. code
  126. } = await getInitDb().toPromise()
  127. if (code * 1 === 200) {
  128. this.isShowInfo = false
  129. this.isProgress = !this.isShowInfo
  130. this.progressPercentage()
  131. this.$emit('click', true)
  132. }
  133. },
  134. async progressPercentage () {
  135. this.interval = setInterval(async () => {
  136. const {
  137. progressBar, type, msg
  138. } = await getProgressPercentage().toPromise()
  139. this.progress.percentage = progressBar * 1
  140. if (type !== 'success') {
  141. this.progress.errorMsg = msg
  142. this.progress.color = '#f56c6c'
  143. } else {
  144. this.progress.msg = msg
  145. this.progress.color = '#409eff'
  146. }
  147. if (progressBar >= 100) {
  148. this.progress.percentage = 100
  149. clearInterval(this.interval)
  150. }
  151. }, 3000)
  152. },
  153. /**
  154. * 格式化 、监听 进度
  155. */
  156. format (percentage) {
  157. if (percentage === 100) {
  158. EventBus.$emit('success', '同步成功请等待重启')
  159. setTimeout(() => {
  160. this.isProgress = false
  161. this.isShowLoadding = !this.isProgress
  162. this.reStart = setInterval(() => {
  163. this.init('wate')
  164. }, 3000)
  165. }, 1000)
  166. }
  167. return `${fmoney(percentage, 1, '')}%`
  168. }
  169. },
  170. mounted () { }
  171. }
  172. </script>
  173. <style lang="scss" scoped>
  174. .schedule {
  175. display: flex;
  176. width: 620px;
  177. height: 222px;
  178. border-radius: 4px;
  179. position: absolute;
  180. top: 50%;
  181. left: 50%;
  182. -webkit-transform: translateX(-50%) translateY(-50%);
  183. -webkit-transform: translateX(-50%) translateY(-50%);
  184. -moz-transform: translateX(-50%) translateY(-50%);
  185. -ms-transform: translateX(-50%) translateY(-50%);
  186. transform: translateX(-50%) translateY(-50%);
  187. z-index: 10000;
  188. padding: 10px;
  189. background: url('./image/bg-button.png') no-repeat right bottom
  190. rgba(255, 255, 255, 1);
  191. div {
  192. display: inline-block;
  193. }
  194. .img {
  195. flex: 1;
  196. background: url('./image/left@2x.png') no-repeat;
  197. background-size: 100% 100%;
  198. padding: 0 20px;
  199. }
  200. .progress {
  201. flex: 3;
  202. margin: auto;
  203. &——bar,
  204. &——loadding {
  205. width: 100%;
  206. }
  207. &——loadding {
  208. text-align: center;
  209. padding-right: 40px;
  210. img {
  211. width: 50px;
  212. height: 50px;
  213. }
  214. }
  215. span {
  216. font-weight: bold;
  217. color: rgba(51, 51, 51, 1);
  218. line-height: 24px;
  219. font-size: 16px;
  220. font-family: Microsoft YaHei;
  221. }
  222. .el-progress {
  223. &--line {
  224. width: 100%;
  225. ::v-deep .el-progress-bar {
  226. &__outer {
  227. background: rgba(220, 233, 255, 1);
  228. }
  229. }
  230. }
  231. &-bar {
  232. padding-right: 55px;
  233. }
  234. &__text {
  235. font-size: 12px;
  236. font-family: Microsoft YaHei;
  237. font-weight: 400;
  238. color: rgba(101, 101, 101, 1);
  239. line-height: 24px;
  240. }
  241. }
  242. .errorMsg {
  243. font-size: 12px;
  244. font-family: Microsoft YaHei;
  245. font-weight: 400;
  246. color: rgba(249, 59, 81, 1);
  247. line-height: 24px;
  248. }
  249. .msg {
  250. font-size: 12px;
  251. font-weight: 400;
  252. line-height: 24px;
  253. }
  254. }
  255. .info {
  256. flex: 3;
  257. font-size: 16px;
  258. font-family: Microsoft YaHei;
  259. font-weight: bold;
  260. p {
  261. color: rgba(51, 51, 51, 1);
  262. line-height: 24px;
  263. margin-top: 60px;
  264. margin-right: 40px;
  265. }
  266. &__footer {
  267. width: 100%;
  268. text-align: center;
  269. button {
  270. width: 180px;
  271. height: 40px;
  272. border: none;
  273. background: linear-gradient(
  274. 65deg,
  275. rgba(110, 212, 255, 1),
  276. rgba(33, 127, 243, 1)
  277. );
  278. border-radius: 20px;
  279. color: rgba(255, 255, 255, 1);
  280. text-shadow: -1px 0px 1px rgba(0, 18, 85, 0.4);
  281. ::v-deep .iconchushihua {
  282. color: #fff;
  283. font-size: 16px;
  284. margin-right: 5px;
  285. }
  286. }
  287. }
  288. }
  289. }
  290. </style>