EntrysManage.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <div>
  3. <div class="menu-title">
  4. 条目管理
  5. </div>
  6. <div class="menu-content">
  7. <div>
  8. <el-form :inline="true" :model="qo" class="demo-form-inline">
  9. <el-form-item>
  10. <el-input v-model="qo.LIKES_categories" placeholder="请输入种类"></el-input>
  11. </el-form-item>
  12. <el-form-item>
  13. <el-input v-model="qo.LIKES_labels" placeholder="请输入标签"></el-input>
  14. </el-form-item>
  15. <el-form-item>
  16. <el-button type="primary" icon="el-icon-search" @click="qo.pageNo=1;queryData()">搜 索</el-button>
  17. </el-form-item>
  18. </el-form>
  19. </div>
  20. <div style="margin: 0px 0 20px 0">
  21. <el-button type="primary" @click="createRow()">添加</el-button>
  22. </div>
  23. <div>
  24. <el-table :data="result.records" style="width: 100%">
  25. <el-table-column type="index" label="行号" width="60"></el-table-column>
  26. <el-table-column prop="fid" label="fid"></el-table-column>
  27. <el-table-column prop="categories" label="种类">
  28. <div slot-scope="scope">
  29. <template v-for="(tag,index) in scope.row.categoriesArr">
  30. <el-tag :key="index" v-if="index < 5">{{ tag }}</el-tag>
  31. </template>
  32. <el-tag v-if="scope.row.categoriesArr.length > 10">...</el-tag>
  33. </div>
  34. </el-table-column>
  35. <el-table-column prop="labels" label="标签">
  36. <div slot-scope="scope">
  37. <template v-for="(tag,index) in scope.row.labelsArr">
  38. <el-tag :key="index" v-if="index < 5">{{ tag }}</el-tag>
  39. </template>
  40. <el-tag v-if="scope.row.labelsArr.length > 5">...</el-tag>
  41. </div>
  42. </el-table-column>
  43. <el-table-column prop="isHidden" label="是否隐藏" width="100">
  44. <template slot-scope="scope">
  45. {{ scope.row.isHidden ? '是' : '否' }}
  46. </template>
  47. </el-table-column>
  48. <el-table-column prop="description" label="描述">
  49. <template slot-scope="scope">
  50. {{ scope.row.description.substring(0, 100) }}{{ scope.row.description.length > 100 ? '...' : '' }}
  51. </template>
  52. </el-table-column>
  53. <el-table-column prop="createTime" label="创建时间" width="180"></el-table-column>
  54. <el-table-column label="操作" width="100">
  55. <template slot-scope="scope">
  56. <el-button @click.native.prevent="modifyRow(scope.row)" type="text" size="small">
  57. 编辑
  58. </el-button>
  59. <el-button @click.native.prevent="removeRow(scope.row)" type="text" size="small">
  60. 删除
  61. </el-button>
  62. </template>
  63. </el-table-column>
  64. </el-table>
  65. </div>
  66. <div class="page-box">
  67. <el-pagination background
  68. @current-change="handleCurrentChange"
  69. :current-page="qo.pageNo"
  70. :page-size="qo.pageSize"
  71. layout="total, prev, pager, next"
  72. :total="result.total">
  73. </el-pagination>
  74. </div>
  75. </div>
  76. <el-dialog
  77. :title="dialogName"
  78. :visible.sync="cmdDialogVisible"
  79. width="40%">
  80. <el-form ref="cmd" label-width="100px" :rules="rules" :model="cmd">
  81. <el-form-item label="fid" prop="fid">
  82. <el-input v-model="cmd.fid" placeholder="请输入fid"></el-input>
  83. </el-form-item>
  84. <el-form-item label="种类">
  85. <el-tag
  86. :key="tag"
  87. v-for="(tag,index) in cmd.categoriesArr"
  88. closable
  89. :disable-transitions="false"
  90. @close="handleTagClose(index, 'categories')">
  91. {{ tag }}
  92. </el-tag>
  93. <el-input
  94. class="input-new-tag"
  95. v-if="categoriesInputVisible"
  96. v-model="categoriesInputValue"
  97. ref="saveCategoriesTagInput"
  98. size="small"
  99. @keyup.enter.native="handleInputConfirm('categories')"
  100. @blur="handleInputConfirm('categories')"
  101. >
  102. </el-input>
  103. <el-button v-else class="button-new-tag" size="small" @click="showInput('categories')">+ 种 类</el-button>
  104. </el-form-item>
  105. <el-form-item label="标签">
  106. <el-tag
  107. :key="tag"
  108. v-for="(tag,index) in cmd.labelsArr"
  109. closable
  110. :disable-transitions="false"
  111. @close="handleTagClose(index, 'labels')">
  112. {{ tag }}
  113. </el-tag>
  114. <el-input
  115. class="input-new-tag"
  116. v-if="labelsInputVisible"
  117. v-model="labelsInputValue"
  118. ref="saveLabelsTagInput"
  119. size="small"
  120. @keyup.enter.native="handleInputConfirm('labels')"
  121. @blur="handleInputConfirm('labels')"
  122. >
  123. </el-input>
  124. <el-button v-else class="button-new-tag" size="small" @click="showInput('labels')">+ 标 签</el-button>
  125. </el-form-item>
  126. <el-form-item label="是否隐藏" prop="isHidden">
  127. <el-radio v-model="cmd.isHidden" :label="true">是</el-radio>
  128. <el-radio v-model="cmd.isHidden" :label="false">否</el-radio>
  129. </el-form-item>
  130. <el-form-item label="描述">
  131. <el-input v-model="cmd.description" placeholder="请输入描述" type="textarea" :rows="5"></el-input>
  132. </el-form-item>
  133. </el-form>
  134. <span slot="footer" class="dialog-footer">
  135. <el-button @click="cmdDialogVisible = false">取 消</el-button>
  136. <el-button type="primary" @click="submitModify">确 定</el-button>
  137. </span>
  138. </el-dialog>
  139. </div>
  140. </template>
  141. <script>
  142. import request from '@/utils/request';
  143. var _this;
  144. export default {
  145. name: "entrys",
  146. data() {
  147. return {
  148. qo: {
  149. pageNo: 1,
  150. pageSize: 10,
  151. LIKES_categories: '',
  152. LIKES_labels: '',
  153. },
  154. result: {
  155. records: [],
  156. total: 0
  157. },
  158. sourceTypeList: [
  159. {name: '自定义本体', value: 1},
  160. {name: '标注系统', value: 2}
  161. ],
  162. dialogName: '编辑',
  163. cmdDialogVisible: false,
  164. cmd: {},
  165. rules: {
  166. fid: [
  167. {required: true, message: '请输入fid'}
  168. ],
  169. isHidden: [
  170. {required: true, message: '请选择是否隐藏'}
  171. ],
  172. },
  173. categoriesInputValue: '',
  174. categoriesInputVisible: false,
  175. labelsInputValue: '',
  176. labelsInputVisible: false
  177. }
  178. },
  179. mounted() {
  180. _this = this;
  181. _this.queryData();
  182. },
  183. methods: {
  184. queryData() {
  185. request({
  186. url: '/entrys/query_pages',
  187. method: 'post',
  188. data: _this.qo
  189. }).then(res => {
  190. res.data.records.forEach(row => {
  191. row.categoriesArr = row.categories ? row.categories.split(',') : [];
  192. row.labelsArr = row.labels ? row.labels.split(',') : [];
  193. });
  194. _this.result.records = res.data.records;
  195. _this.result.total = res.data.total;
  196. });
  197. },
  198. handleCurrentChange(val) {
  199. _this.qo.pageNo = val;
  200. _this.queryData();
  201. },
  202. removeRow(item) {
  203. _this.$confirm('此操作将永久删除记录, 是否继续?', '提示', {
  204. confirmButtonText: '确定',
  205. cancelButtonText: '取消',
  206. type: 'warning'
  207. }).then(() => {
  208. request({
  209. url: '/entrys/remove/' + item.id,
  210. method: 'post'
  211. }).then(res => {
  212. _this.$message.success("删除成功");
  213. _this.queryData();
  214. });
  215. }).catch(() => {
  216. });
  217. },
  218. createRow() {
  219. _this.dialogName = '新建';
  220. _this.cmdDialogVisible = true;
  221. _this.$nextTick(_=> {
  222. _this.$refs['cmd'].clearValidate();
  223. _this.cmd = {
  224. fid: '',
  225. isHidden: false,
  226. categoriesArr: [],
  227. labelsArr: [],
  228. description: ''
  229. };
  230. })
  231. },
  232. modifyRow(item) {
  233. _this.dialogName = '编辑';
  234. _this.cmdDialogVisible = true;
  235. _this.$nextTick(_=> {
  236. _this.$refs['cmd'].clearValidate();
  237. _this.cmd = JSON.parse(JSON.stringify(item));
  238. })
  239. },
  240. submitModify() {
  241. this.$refs.cmd.validate((valid) => {
  242. if (valid) {
  243. if(_this.cmd.categoriesArr) {
  244. _this.cmd.categories = _this.cmd.categoriesArr.toString();
  245. }
  246. if(_this.cmd.labelsArr) {
  247. _this.cmd.labels = _this.cmd.labelsArr.toString();
  248. }
  249. if (_this.cmd.id) {
  250. request({
  251. url: '/entrys/modify',
  252. method: 'post',
  253. data: _this.cmd
  254. }).then(res => {
  255. _this.$message.success("编辑成功");
  256. _this.queryData();
  257. _this.cmdDialogVisible = false;
  258. });
  259. } else { // 新建
  260. request({
  261. url: '/entrys/create',
  262. method: 'post',
  263. data: _this.cmd
  264. }).then(res => {
  265. _this.$message.success("添加成功");
  266. _this.cmdDialogVisible = false;
  267. });
  268. }
  269. }
  270. });
  271. },
  272. showInput(typeName) {
  273. if (typeName === 'categories') {
  274. this.categoriesInputVisible = true;
  275. this.$nextTick(_ => {
  276. this.$refs.saveCategoriesTagInput.$refs.input.focus();
  277. });
  278. } else if (typeName === 'labels') {
  279. this.labelsInputVisible = true;
  280. this.$nextTick(_ => {
  281. this.$refs.saveLabelsTagInput.$refs.input.focus();
  282. });
  283. }
  284. },
  285. handleTagClose(index, typeName) {
  286. _this.cmd[typeName + "Arr"].splice(index, 1);
  287. },
  288. handleInputConfirm(typeName) {
  289. let inputValue = _this[typeName + "InputValue"];
  290. if(inputValue) {
  291. _this.cmd[typeName + "Arr"].push(inputValue);
  292. }
  293. _this[typeName + "InputVisible"] = false;
  294. _this[typeName + "InputValue"] = "";
  295. }
  296. }
  297. }
  298. </script>
  299. <style lang="scss">
  300. .input-new-tag {
  301. margin-bottom: 12px;
  302. height: 32px;
  303. width: 80px;
  304. input {
  305. height: 32px !important;
  306. width: 80px;
  307. }
  308. }
  309. .el-tag {
  310. margin-right: 10px;
  311. margin-bottom: 10px;
  312. height: 32px;
  313. }
  314. .button-new-tag {
  315. line-height: 30px;
  316. padding-top: 0;
  317. padding-bottom: 0;
  318. }
  319. </style>