StreamProxyEdit.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. // var deviceGBIdRules = async (rule, value, callback) => {
  130. // console.log(value);
  131. // if (value === "") {
  132. // callback(new Error("请输入设备国标编号"));
  133. // } else {
  134. // var exit = await this.deviceGBIdExit(value);
  135. // console.log(exit);
  136. // console.log(exit == "true");
  137. // console.log(exit === "true");
  138. // if (exit) {
  139. // callback(new Error("设备国标编号已存在"));
  140. // } else {
  141. // callback();
  142. // }
  143. // }
  144. // };
  145. return {
  146. listChangeCallback: null,
  147. showDialog: false,
  148. isLoging: false,
  149. dialogLoading: false,
  150. onSubmit_text: "立即创建",
  151. platformList: [],
  152. mediaServer: new MediaServer(),
  153. proxyParam: {
  154. name: null,
  155. type: "default",
  156. app: null,
  157. stream: null,
  158. url: "",
  159. src_url: null,
  160. timeout_ms: null,
  161. ffmpeg_cmd_key: null,
  162. gbId: null,
  163. rtp_type: null,
  164. enable: true,
  165. enable_hls: true,
  166. enable_mp4: false,
  167. enable_remove_none_reader: false,
  168. platformGbId: null,
  169. mediaServerId: null,
  170. },
  171. mediaServerList:{},
  172. ffmpegCmdList:{},
  173. rules: {
  174. name: [{ required: true, message: "请输入名称", trigger: "blur" }],
  175. app: [{ required: true, message: "请输入应用名", trigger: "blur" }],
  176. stream: [{ required: true, message: "请输入流ID", trigger: "blur" }],
  177. url: [{ required: true, message: "请输入要代理的流", trigger: "blur" }],
  178. src_url: [{ required: true, message: "请输入要代理的流", trigger: "blur" }],
  179. timeout_ms: [{ required: true, message: "请输入FFmpeg推流成功超时时间", trigger: "blur" }],
  180. ffmpeg_cmd_key: [{ required: false, message: "请输入FFmpeg命令参数模板(可选)", trigger: "blur" }],
  181. },
  182. };
  183. },
  184. methods: {
  185. openDialog: function (proxyParam, callback) {
  186. this.showDialog = true;
  187. this.listChangeCallback = callback;
  188. if (proxyParam != null) {
  189. this.proxyParam = proxyParam;
  190. }
  191. let that = this;
  192. this.$axios({
  193. method: 'get',
  194. url:`/api/platform/query/10000/1`
  195. }).then(function (res) {
  196. that.platformList = res.data.list;
  197. }).catch(function (error) {
  198. console.log(error);
  199. });
  200. this.mediaServer.getOnlineMediaServerList((data)=>{
  201. this.mediaServerList = data.data;
  202. this.proxyParam.mediaServerId = this.mediaServerList[0].id
  203. this.mediaServerIdChange()
  204. })
  205. },
  206. mediaServerIdChange:function (){
  207. let that = this;
  208. if (that.proxyParam.mediaServerId !== "auto"){
  209. that.$axios({
  210. method: 'get',
  211. url:`/api/proxy/ffmpeg_cmd/list`,
  212. params: {
  213. mediaServerId: that.proxyParam.mediaServerId
  214. }
  215. }).then(function (res) {
  216. that.ffmpegCmdList = res.data.data;
  217. that.proxyParam.ffmpeg_cmd_key = Object.keys(res.data.data)[0];
  218. }).catch(function (error) {
  219. console.log(error);
  220. });
  221. }
  222. },
  223. onSubmit: function () {
  224. this.dialogLoading = true;
  225. var that = this;
  226. that.$axios({
  227. method: 'post',
  228. url:`/api/proxy/save`,
  229. data: that.proxyParam
  230. }).then(function (res) {
  231. that.dialogLoading = false;
  232. if (typeof (res.data.code) != "undefined" && res.data.code === 0) {
  233. that.$message({
  234. showClose: true,
  235. message: res.data.msg,
  236. type: "success",
  237. });
  238. that.showDialog = false;
  239. if (that.listChangeCallback != null) {
  240. that.listChangeCallback();
  241. that.dialogLoading = false;
  242. }
  243. }
  244. }).catch(function (error) {
  245. console.log(error);
  246. this.dialogLoading = false;
  247. });
  248. },
  249. close: function () {
  250. this.showDialog = false;
  251. this.dialogLoading = false;
  252. this.$refs.streamProxy.resetFields();
  253. },
  254. deviceGBIdExit: async function (deviceGbId) {
  255. var result = false;
  256. var that = this;
  257. await that.$axios({
  258. method: 'post',
  259. url:`/api/platform/exit/${deviceGbId}`
  260. }).then(function (res) {
  261. result = res.data;
  262. }).catch(function (error) {
  263. console.log(error);
  264. });
  265. return result;
  266. },
  267. checkExpires: function() {
  268. if (this.platform.enable && this.platform.expires == "0") {
  269. this.platform.expires = "300";
  270. }
  271. }
  272. },
  273. };
  274. </script>