createConfig.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <div id="aiConfig w-full" style="width:100%">
  3. <div class="page-header">
  4. <div class="page-title">
  5. <el-button icon="el-icon-back" size="mini" style="font-size: 20px; color: #000;" type="text" @click="toBack" ></el-button>
  6. <el-divider direction="vertical"></el-divider>
  7. 创建ai配置:
  8. <el-select v-model="aiTypeVal" @change="getNowAiLib" placeholder="请选择">
  9. <el-option
  10. v-for="item in aiTypeArr"
  11. :key="item.val"
  12. :label="item.text"
  13. :value="item.val"
  14. :disabled="item.disabled">
  15. </el-option>
  16. </el-select>
  17. </div>
  18. <div class="page-header-btn">
  19. </div>
  20. </div>
  21. <el-container v-loading="isLoading" style="min-height: 82vh;flex-direction: column;" >
  22. <el-card class="box-card mt-5">
  23. <div slot="header" class="card-header flex space-between align-center" >
  24. <span>输入配置对应参数</span>
  25. </div>
  26. <div class="box-center">
  27. <div class="line">
  28. <div class="label">检测类型</div>
  29. <div class="input">
  30. <el-select v-model="triggerType" placeholder="请选择" no-data-text="无法加载类型库">
  31. <el-option
  32. v-for="item in triggerTypeArr"
  33. :key="item.val"
  34. :label="item.text"
  35. :value="item.val"
  36. :disabled="aiTypeVal===aiTypes.fire && (item.val !== triggerTypes.unlimited)">
  37. </el-option>
  38. </el-select>
  39. <el-tooltip class="item" effect="dark" content="创建新数据库" placement="left-start">
  40. <el-button icon="el-icon-plus" size="mini" style="font-size: 20px; color: #000;" type="text" @click="toAddLibrary" ></el-button>
  41. </el-tooltip>
  42. </div>
  43. </div>
  44. <div class="line" v-if="triggerType !== triggerTypes.unlimited ">
  45. <div class="label">图形库</div>
  46. <div class="input">
  47. <el-select v-model="libraryId" placeholder="请选择" no-data-text="暂时没有算法库">
  48. <el-option
  49. v-for="item in nowAiLib"
  50. :key="item.libraryId"
  51. :label="item.libraryName"
  52. :value="item.libraryId"
  53. :disabled="item.disabled">
  54. </el-option>
  55. </el-select>
  56. <el-tooltip class="item" effect="dark" content="创建新数据库" placement="left-start">
  57. <el-button icon="el-icon-plus" size="mini" style="font-size: 20px; color: #000;" type="text" @click="toAddLibrary" ></el-button>
  58. </el-tooltip>
  59. </div>
  60. </div>
  61. <div class="line">
  62. <div class="label">数据刷新时间</div>
  63. <div class="input">
  64. <el-input-number v-model="refreshTime" controls-position="right" :min="10" :max="9999"></el-input-number>
  65. <span class="ml-3.5">/秒</span>
  66. </div>
  67. </div>
  68. <div class="line">
  69. <div class="label">配置名称</div>
  70. <div class="input">
  71. <el-input placeholder="该配置展示给其他界面的名称" v-model="configName"/>
  72. </div>
  73. </div>
  74. <div class="line">
  75. <div class="label">检测阈值</div>
  76. <div class="input">
  77. <el-input-number v-model="score" controls-position="right" :min="1" :step="0.1" :max="99"></el-input-number>
  78. <span class="ml-3.5">%</span>
  79. </div>
  80. </div>
  81. <div class="line">
  82. <div class="label">资源获取地址</div>
  83. <div class="input">
  84. <el-input placeholder="使用默认地址" v-model="resourcePath"/>
  85. </div>
  86. </div>
  87. <div class="line">
  88. <div class="label">多媒体数据上传地址</div>
  89. <div class="input">
  90. <el-input placeholder="使用默认地址" v-model="uploadUrl"/>
  91. </div>
  92. </div>
  93. <div class="line">
  94. <div class="label">回调数据地址</div>
  95. <div class="input">
  96. <el-input placeholder="默认不启用" v-model="pushUrl"/>
  97. </div>
  98. </div>
  99. </div>
  100. <el-divider></el-divider>
  101. <el-button-group>
  102. <el-button @click="init">重置</el-button>
  103. <el-button @click="submitData" type="primary">确认添加</el-button>
  104. </el-button-group>
  105. </el-card>
  106. </el-container>
  107. </div>
  108. </template>
  109. <script>
  110. import handle from "@/until/handle";
  111. import {toNumber} from "@/until/typeTool";
  112. import aiMap from "@/map/ai";
  113. export default {
  114. name: "createConfig",
  115. data(){
  116. return {
  117. aiTypes: aiMap.aiTypes,
  118. aiTypeArr: aiMap.getAITypeArr(),
  119. triggerTypes: aiMap.triggerTypes,
  120. triggerTypeArr: aiMap.getTriggerTypeArr(),
  121. aiTypeVal: 0,
  122. arithmetic: this.$route.params.arithmetic,
  123. isLoading:false,
  124. aiLibList: [],
  125. nowAiLib: [],
  126. configName: '',
  127. libraryId: 0,
  128. triggerType: 1,
  129. refreshTime: 60,
  130. score: 75.5,
  131. resourcePath: "",
  132. uploadUrl: "",
  133. pushUrl: "",
  134. errorTip: "",
  135. }
  136. },
  137. mounted() {
  138. // console.log('******************');
  139. this.init();
  140. this.loadAiLib();
  141. },
  142. methods:{
  143. toArithmetic: aiMap.toArithmetic,
  144. toTriggerType: aiMap.toTriggerType,
  145. init(){
  146. this.arithmetic = this.$route.params.arithmetic || this.aiTypeArr[0].val;
  147. this.arithmetic = toNumber(this.arithmetic);
  148. this.aiTypeVal = this.arithmetic;
  149. this.libraryId = 0;
  150. this.configName= '';
  151. this.libraryId= 0;
  152. this.triggerType= 1;
  153. this.refreshTime= 60;
  154. this.score= 75.5;
  155. this.resourcePath= "";
  156. this.uploadUrl= "";
  157. this.pushUrl= "";
  158. this.errorTip= "";
  159. // console.log(this.aiTypeVal);
  160. },
  161. toBack(){
  162. this.$router.back();
  163. if (this.deviceId === "" ) {
  164. this.beforeUrl = "/deviceList"
  165. }
  166. },
  167. async loadAiLib(){
  168. this.isLoading = true;
  169. let that = this;
  170. let [err,res] = await handle(this.$axios({
  171. method: 'get',
  172. url: `/api/device/query/aiLibrary`
  173. }))
  174. this.isLoading = false;
  175. if (err){
  176. console.error(err)
  177. that.$message({
  178. showClose: true,
  179. message: err,
  180. type: 'error'
  181. });
  182. return;
  183. }
  184. let data = res.data;
  185. if(data.code === 0 ){
  186. that.aiLibList = data.data;
  187. }else{
  188. console.log(res);
  189. console.error("未知的返回结果!")
  190. }
  191. },
  192. toAiData(num){
  193. num=toNumber(num);
  194. console.log(this.aiLibList);
  195. let key = Object.keys(this.aiLibList).find(key=>toNumber(this.aiLibList[key].libraryId)===num);
  196. return key?this.aiLibList[key]:false;
  197. },
  198. getNowAiLib(){
  199. this.nowAiLib = this.aiLibList.filter(aiLib=>toNumber(aiLib.libraryId)===toNumber(this.aiTypeVal));
  200. this.libraryId = 0;
  201. this.triggerType = this.triggerTypes.unlimited;
  202. console.log("------");
  203. console.log(this.nowAiLib);
  204. },
  205. toAddLibrary(){
  206. },
  207. // 构建数据结构体
  208. async submitData(){
  209. if(!this.arithmetic){return this.$message.warning('未选择算法')}
  210. if(!this.triggerType){return this.$message.warning('未选择触发类型')}
  211. if(this.triggerType!==this.triggerTypes.unlimited && !this.libraryId){return this.$message.warning('未选择对应的数据库')}
  212. let data = {};
  213. data.configName = this.configName;
  214. data.arithmetic = this.aiTypeVal;
  215. data.triggerType = this.triggerType;
  216. data.score = this.score;
  217. data.refreshTime = this.refreshTime;
  218. data.resourcePath = this.resourcePath;
  219. data.uploadUrl = this.uploadUrl;
  220. data.pushUrl = this.pushUrl;
  221. this.isLoading = true;
  222. let [err,res] = handle(this.$axios({
  223. method: 'post',
  224. url: '/api/device/query/addAiConfig',
  225. data:data
  226. }));
  227. this.isLoading = false;
  228. if(err){
  229. console.error(err)
  230. this.$message({
  231. showClose: true,
  232. message: err,
  233. type: 'error'
  234. });
  235. return;
  236. }
  237. console.log(res);
  238. this.$message.success("创建成功!!!");
  239. this.init();
  240. }
  241. }
  242. }
  243. </script>
  244. <style scoped>
  245. .box-center{
  246. width:100%;
  247. height: auto;
  248. }
  249. .box-center{
  250. width: 100%;
  251. height: auto;
  252. padding: 10px 5px;
  253. box-sizing: border-box;
  254. }
  255. .box-center .line{
  256. width: 100%;
  257. height: 35px;
  258. display: flex;
  259. margin-bottom: 10px;
  260. }
  261. .box-center .line .label{
  262. width: 20%;
  263. height: 100%;
  264. display: flex;
  265. justify-content: center;
  266. align-items: center;
  267. }
  268. .box-center .line .input{
  269. width: 80%;
  270. height: 100%;
  271. display: flex;
  272. align-items: center;
  273. box-sizing: border-box;
  274. padding-left: 8px;
  275. border-left: 1px solid grey;
  276. }
  277. </style>