StreamProxyEdit.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <div id="addStreamProxy" v-loading="isLoging">
  3. <el-dialog
  4. title="添加代理"
  5. width="40%"
  6. top="2rem"
  7. :close-on-click-modal="false"
  8. :visible.sync="showDialog"
  9. :destroy-on-close="true"
  10. @close="close()"
  11. >
  12. <div id="shared" style="margin-top: 1rem;margin-right: 100px;">
  13. <el-form ref="streamProxy" :rules="rules" :model="proxyParam" label-width="140px" >
  14. <el-form-item label="类型" prop="type">
  15. <el-select
  16. v-model="proxyParam.type"
  17. style="width: 100%"
  18. placeholder="请选择代理类型"
  19. >
  20. <el-option label="默认" value="default"></el-option>
  21. <el-option label="FFmpeg" value="ffmpeg"></el-option>
  22. </el-select>
  23. </el-form-item>
  24. <el-form-item label="名称" prop="name">
  25. <el-input v-model="proxyParam.name" clearable></el-input>
  26. </el-form-item>
  27. <el-form-item label="流应用名" prop="app">
  28. <el-input v-model="proxyParam.app" clearable></el-input>
  29. </el-form-item>
  30. <el-form-item label="流ID" prop="stream">
  31. <el-input v-model="proxyParam.stream" clearable></el-input>
  32. </el-form-item>
  33. <el-form-item label="拉流地址" prop="url" v-if="proxyParam.type=='default'">
  34. <el-input v-model="proxyParam.url" clearable></el-input>
  35. </el-form-item>
  36. <el-form-item label="拉流地址" prop="src_url" v-if="proxyParam.type=='ffmpeg'">
  37. <el-input v-model="proxyParam.src_url" clearable></el-input>
  38. </el-form-item>
  39. <el-form-item label="超时时间:毫秒" prop="timeout_ms" v-if="proxyParam.type=='ffmpeg'">
  40. <el-input v-model="proxyParam.timeout_ms" clearable></el-input>
  41. </el-form-item>
  42. <el-form-item label="节点选择" prop="rtp_type">
  43. <el-select
  44. v-model="proxyParam.mediaServerId"
  45. @change="mediaServerIdChange"
  46. style="width: 100%"
  47. placeholder="请选择拉流节点"
  48. >
  49. <el-option
  50. v-for="item in mediaServerList"
  51. :key="item.id"
  52. :label="item.id"
  53. :value="item.id">
  54. </el-option>
  55. </el-select>
  56. </el-form-item>
  57. <el-form-item label="FFmpeg命令模板" prop="ffmpeg_cmd_key" v-if="proxyParam.type=='ffmpeg'">
  58. <!-- <el-input v-model="proxyParam.ffmpeg_cmd_key" clearable></el-input>-->
  59. <el-select
  60. v-model="proxyParam.ffmpeg_cmd_key"
  61. style="width: 100%"
  62. placeholder="请选择FFmpeg命令模板"
  63. >
  64. <el-option
  65. v-for="item in Object.keys(ffmpegCmdList)"
  66. :key="item"
  67. :label="ffmpegCmdList[item]"
  68. :value="item">
  69. </el-option>
  70. </el-select>
  71. </el-form-item>
  72. <el-form-item label="国标编码" prop="gbId">
  73. <el-input v-model="proxyParam.gbId" placeholder="设置国标编码可推送到国标" clearable></el-input>
  74. </el-form-item>
  75. <el-form-item label="拉流方式" prop="rtp_type" v-if="proxyParam.type=='default'">
  76. <el-select
  77. v-model="proxyParam.rtp_type"
  78. style="width: 100%"
  79. placeholder="请选择拉流方式"
  80. >
  81. <el-option label="TCP" value="0"></el-option>
  82. <el-option label="UDP" value="1"></el-option>
  83. <el-option label="组播" value="2"></el-option>
  84. </el-select>
  85. </el-form-item>
  86. <el-form-item label="国标平台">
  87. <el-select
  88. v-model="proxyParam.platformGbId"
  89. style="width: 100%"
  90. placeholder="请选择国标平台"
  91. >
  92. <el-option
  93. v-for="item in platformList"
  94. :key="item.name"
  95. :label="item.name"
  96. :value="item.serverGBId">
  97. <span style="float: left">{{ item.name }}</span>
  98. <span style="float: right; color: #8492a6; font-size: 13px">{{ item.serverGBId }}</span>
  99. </el-option>
  100. </el-select>
  101. </el-form-item>
  102. <el-form-item label="其他选项">
  103. <div style="float: left;">
  104. <el-checkbox label="启用" v-model="proxyParam.enable" ></el-checkbox>
  105. <el-checkbox label="转HLS" v-model="proxyParam.enable_hls" ></el-checkbox>
  106. <el-checkbox label="MP4录制" v-model="proxyParam.enable_mp4" ></el-checkbox>
  107. <el-checkbox label="无人观看自动删除" v-model="proxyParam.enable_remove_none_reader" ></el-checkbox>
  108. </div>
  109. </el-form-item>
  110. <el-form-item>
  111. <div style="float: right;">
  112. <el-button type="primary" @click="onSubmit" :loading="dialogLoading" >{{onSubmit_text}}</el-button>
  113. <el-button @click="close">取消</el-button>
  114. </div>
  115. </el-form-item>
  116. </el-form>
  117. </div>
  118. </el-dialog>
  119. </div>
  120. </template>
  121. <script>
  122. import MediaServer from './../service/MediaServer'
  123. export default {
  124. name: "streamProxyEdit",
  125. props: {},
  126. computed: {},
  127. created() {},
  128. data() {
  129. return {
  130. listChangeCallback: null,
  131. showDialog: false,
  132. isLoging: false,
  133. dialogLoading: false,
  134. onSubmit_text: "立即创建",
  135. platformList: [],
  136. mediaServer: new MediaServer(),
  137. proxyParam: {
  138. name: null,
  139. type: "default",
  140. app: null,
  141. stream: null,
  142. url: "",
  143. src_url: null,
  144. timeout_ms: null,
  145. ffmpeg_cmd_key: null,
  146. gbId: null,
  147. rtp_type: null,
  148. enable: true,
  149. enable_hls: true,
  150. enable_mp4: false,
  151. enable_remove_none_reader: false,
  152. platformGbId: null,
  153. mediaServerId: null,
  154. },
  155. mediaServerList:{},
  156. ffmpegCmdList:{},
  157. rules: {
  158. name: [{ required: true, message: "请输入名称", trigger: "blur" }],
  159. app: [{ required: true, message: "请输入应用名", trigger: "blur" }],
  160. stream: [{ required: true, message: "请输入流ID", trigger: "blur" }],
  161. url: [{ required: true, message: "请输入要代理的流", trigger: "blur" }],
  162. src_url: [{ required: true, message: "请输入要代理的流", trigger: "blur" }],
  163. timeout_ms: [{ required: true, message: "请输入FFmpeg推流成功超时时间", trigger: "blur" }],
  164. ffmpeg_cmd_key: [{ required: false, message: "请输入FFmpeg命令参数模板(可选)", trigger: "blur" }],
  165. },
  166. isUpdate: false,
  167. };
  168. },
  169. methods: {
  170. openDialog: function (proxyParam, callback) {
  171. this.showDialog = true;
  172. this.listChangeCallback = callback;
  173. if (proxyParam != null) {
  174. this.isUpdate=true
  175. this.proxyParam = proxyParam;
  176. }
  177. let that = this;
  178. this.$axios({
  179. method: 'get',
  180. url:`/api/platform/query/10000/1`
  181. }).then(function (res) {
  182. that.platformList = res.data.list;
  183. }).catch(function (error) {
  184. console.log(error);
  185. });
  186. this.mediaServer.getOnlineMediaServerList((data)=>{
  187. this.mediaServerList = data.data;
  188. this.proxyParam.mediaServerId = this.mediaServerList[0].id
  189. this.mediaServerIdChange()
  190. })
  191. },
  192. mediaServerIdChange:function (){
  193. let that = this;
  194. if (that.proxyParam.mediaServerId !== "auto"){
  195. that.$axios({
  196. method: 'get',
  197. url:`/api/proxy/ffmpeg_cmd/list`,
  198. params: {
  199. mediaServerId: that.proxyParam.mediaServerId
  200. }
  201. }).then(function (res) {
  202. that.ffmpegCmdList = res.data.data;
  203. that.proxyParam.ffmpeg_cmd_key = Object.keys(res.data.data)[0];
  204. }).catch(function (error) {
  205. console.log(error);
  206. });
  207. }
  208. },
  209. onSubmit: function () {
  210. this.dialogLoading = true;
  211. var that = this;
  212. if(this.isUpdate){
  213. that.$axios({
  214. method: 'post',
  215. url:`/api/proxy/update`,
  216. data: that.proxyParam
  217. }).then(function (res) {
  218. that.dialogLoading = false;
  219. if (typeof (res.data.code) != "undefined" && res.data.code === 0) {
  220. that.$message({
  221. showClose: true,
  222. message: res.data.msg,
  223. type: "success",
  224. });
  225. that.showDialog = false;
  226. if (that.listChangeCallback != null) {
  227. that.listChangeCallback();
  228. that.dialogLoading = false;
  229. }
  230. }
  231. }).catch(function (error) {
  232. console.log(error);
  233. this.dialogLoading = false;
  234. });
  235. }else{
  236. that.$axios({
  237. method: 'post',
  238. url:`/api/proxy/save`,
  239. data: that.proxyParam
  240. }).then(function (res) {
  241. that.dialogLoading = false;
  242. if (typeof (res.data.code) != "undefined" && res.data.code === 0) {
  243. that.$message({
  244. showClose: true,
  245. message: res.data.msg,
  246. type: "success",
  247. });
  248. that.showDialog = false;
  249. if (that.listChangeCallback != null) {
  250. that.listChangeCallback();
  251. that.dialogLoading = false;
  252. }
  253. }
  254. }).catch(function (error) {
  255. console.log(error);
  256. this.dialogLoading = false;
  257. });
  258. }
  259. },
  260. close: function () {
  261. this.showDialog = false;
  262. this.dialogLoading = false;
  263. this.$refs.streamProxy.resetFields();
  264. },
  265. deviceGBIdExit: async function (deviceGbId) {
  266. var result = false;
  267. var that = this;
  268. await that.$axios({
  269. method: 'post',
  270. url:`/api/platform/exit/${deviceGbId}`
  271. }).then(function (res) {
  272. result = res.data;
  273. }).catch(function (error) {
  274. console.log(error);
  275. });
  276. return result;
  277. },
  278. checkExpires: function() {
  279. if (this.platform.enable && this.platform.expires == "0") {
  280. this.platform.expires = "300";
  281. }
  282. }
  283. },
  284. };
  285. </script>