chat.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <template>
  2. <div v-if="type == 'image'">
  3. <!-- <ul v-for="(item,index) in value" :key="index" class="el-upload-list el-upload-list--picture-card">
  4. <li tabindex="0" class="el-upload-list__item is-ready" :style="'width: '+width+'px;height: '+height+'px'">
  5. <div>
  6. <img :src="item" alt="" class="el-upload-list__item-thumbnail">
  7. <span class="el-upload-list__item-actions">
  8. <span v-if="index != 0" class="el-upload-list__item-preview" @click="moveMaterial(index,'up')">
  9. <i class="el-icon-back" />
  10. </span>
  11. <span class="el-upload-list__item-preview" @click="zoomMaterial(index)">
  12. <i class="el-icon-view" />
  13. </span>
  14. <span class="el-upload-list__item-delete" @click="deleteMaterial(index)">
  15. <i class="el-icon-delete" />
  16. </span>
  17. <span v-if="index != value.length-1" class="el-upload-list__item-preview" @click="moveMaterial(index,'down')">
  18. <i class="el-icon-right" />
  19. </span>
  20. </span>
  21. </div>
  22. </li>
  23. </ul>
  24. <div v-if="num > value.length" tabindex="0" class="el-upload el-upload--picture-card" :style="'width: '+width+'px;height: '+height+'px;'+'line-height:'+height+'px;'" @click="toSeleteMaterial">
  25. <i class="el-icon-plus" />
  26. </div> -->
  27. <!-- 查看 -->
  28. <el-dialog
  29. append-to-body
  30. :visible.sync="dialogVisible"
  31. width="35%">
  32. <img :src="url" alt="" style="width: 100%">
  33. </el-dialog>
  34. <!-- 素材列表 -->
  35. <el-dialog
  36. title="图片素材库"
  37. append-to-body
  38. :visible.sync="listDialogVisible"
  39. width="70%">
  40. <el-container>
  41. <el-aside width="unset">
  42. <div style="margin-bottom: 10px">
  43. <el-button
  44. class="el-icon-plus"
  45. size="small"
  46. @click="materialgroupAdd()">
  47. 添加分组
  48. </el-button>
  49. </div>
  50. <div class="group-list">
  51. <div class="group-item" v-for="(group) in materialGroupList">
  52. <el-button @click="selectGroup(group)" type="primary" plain >{{group.name}}</el-button>
  53. </div>
  54. </div>
  55. </el-aside>
  56. <el-main>
  57. <el-card>
  58. <div slot="header">
  59. <el-row>
  60. <el-col :span="12">
  61. <span>{{ materialGroup.name }}</span>
  62. <span v-if="materialGroup.groupId >0">
  63. <el-button size="small" type="text" class="el-icon-edit" style="margin-left: 10px;" @click="materialgroupEdit(materialGroup)">重命名</el-button>
  64. <el-button size="small" type="text" class="el-icon-delete" style="margin-left: 10px;color: red" @click="materialgroupDelete(materialGroup)">删除</el-button>
  65. </span>
  66. </el-col>
  67. <el-col :span="12" style="text-align: right;">
  68. <el-upload
  69. :action="uploadUrl"
  70. :file-list="[]"
  71. :on-progress="handleProgress"
  72. :before-upload="beforeUpload"
  73. :on-success="handleSuccess"
  74. :data="multipartFile"
  75. multiple>
  76. <el-button size="small" type="primary">批量上传</el-button>
  77. </el-upload>
  78. </el-col>
  79. </el-row>
  80. </div>
  81. <div v-loading="tableLoading">
  82. <el-alert
  83. v-if="tableData.length <= 0"
  84. title="暂无数据"
  85. type="info"
  86. :closable="false"
  87. center
  88. show-icon/>
  89. <el-row :gutter="5">
  90. <el-checkbox-group v-model="urls" :max="num - value.length">
  91. <el-col v-for="(item,index) in tableData" :key="index" :span="4" >
  92. <el-card :body-style="{ padding: '5px' }">
  93. <el-image
  94. style="width: 100%;height: 100px"
  95. :src="item.url"
  96. fit="contain"
  97. :preview-src-list="[item.url]"
  98. :z-index="9999" />
  99. <div>
  100. <el-checkbox class="material-name" :label="item.url">
  101. 选择
  102. </el-checkbox>
  103. <el-row>
  104. <el-col :span="24" class="col-do">
  105. <el-button type="text" size="medium" @click="materialDel(item)">删除</el-button>
  106. </el-col>
  107. </el-row>
  108. </div>
  109. </el-card>
  110. </el-col>
  111. </el-checkbox-group>
  112. </el-row>
  113. <pagination
  114. v-show="total>0"
  115. :total="total"
  116. :page.sync="queryParams.pageNum"
  117. :limit.sync="queryParams.pageSize"
  118. @pagination="getMaterialList"/>
  119. </div>
  120. </el-card>
  121. </el-main>
  122. </el-container>
  123. <span slot="footer" class="dialog-footer">
  124. <el-button @click="listDialogVisible = false">取 消</el-button>
  125. <el-button type="primary" @click="submit">确 定</el-button>
  126. </span>
  127. </el-dialog>
  128. </div>
  129. </template>
  130. <script>
  131. import { listMaterial, getMaterial, delMaterial, addMaterial, updateMaterial, exportMaterial } from "@/api/store/material";
  132. import { getAllMaterialGroup,listMaterialGroup, getMaterialGroup, delMaterialGroup, addMaterialGroup, updateMaterialGroup, exportMaterialGroup } from "@/api/store/materialGroup";
  133. export default {
  134. name: 'ImageSelect',
  135. props: {
  136. // 素材数据
  137. value: {
  138. type: Array,
  139. default() {
  140. return []
  141. }
  142. },
  143. // 素材类型
  144. type: {
  145. type: String
  146. },
  147. // 素材限制数量,默认5个
  148. num: {
  149. type: Number,
  150. default() {
  151. return 5
  152. }
  153. },
  154. // 宽度
  155. width: {
  156. type: Number,
  157. default() {
  158. return 150
  159. }
  160. },
  161. // 宽度
  162. height: {
  163. type: Number,
  164. default() {
  165. return 150
  166. }
  167. }
  168. },
  169. data() {
  170. return {
  171. multipartFile:{},
  172. uploadUrl:process.env.VUE_APP_BASE_API+"/common/qwUploadOSS",
  173. dialogVisible: false,
  174. url: '',
  175. listDialogVisible: false,
  176. materialGroupList: [],
  177. materialGroupLoading: false,
  178. materialGroup:{},
  179. tableData: [],
  180. resultNumber: 0,
  181. total: 0,
  182. queryParams: {
  183. pageNum: 1,
  184. pageSize: 10,
  185. type: null,
  186. groupId: null,
  187. name: null,
  188. url: null,
  189. isDel: null,
  190. createUserId: null,
  191. },
  192. tableLoading: false,
  193. urls: []
  194. }
  195. },
  196. mounted(){
  197. this.getAllMaterialGroup();
  198. },
  199. methods: {
  200. openMaterial(deviceid){
  201. var mpartFile={deviceId:deviceid};
  202. this.multipartFile=mpartFile;
  203. this.toSeleteMaterial();
  204. },
  205. selectGroup(item){
  206. this.materialGroup=item;
  207. this.queryParams.groupId=item.groupId;
  208. this.getMaterialList();
  209. },
  210. materialgroupAdd() {
  211. const that = this
  212. this.$prompt('请输入分组名', '提示', {
  213. confirmButtonText: '确定',
  214. cancelButtonText: '取消'
  215. }).then(({ value }) => {
  216. addMaterialGroup({
  217. name: value
  218. }).then(function() {
  219. that.materialGroup={};
  220. that.getAllMaterialGroup()
  221. })
  222. }).catch(() => {
  223. })
  224. },
  225. materialgroupDelete(materialgroupObj) {
  226. const that = this
  227. this.$confirm('是否确认删除该分组?', '提示', {
  228. confirmButtonText: '确定',
  229. cancelButtonText: '取消',
  230. type: 'warning'
  231. }).then(function() {
  232. delMaterialGroup(materialgroupObj.groupId)
  233. .then(function() {
  234. that.materialGroup={};
  235. that.getAllMaterialGroup()
  236. })
  237. })
  238. },
  239. materialgroupEdit(materialgroupObj) {
  240. const that = this
  241. this.$prompt('请输入分组名', '提示', {
  242. confirmButtonText: '确定',
  243. cancelButtonText: '取消',
  244. inputValue: materialgroupObj.name
  245. }).then(({ value }) => {
  246. updateMaterialGroup({
  247. groupId: materialgroupObj.groupId,
  248. name: value
  249. }).then(function() {
  250. that.materialGroup={};
  251. that.getAllMaterialGroup()
  252. })
  253. }).catch(() => {
  254. })
  255. },
  256. getAllMaterialGroup() {
  257. this.materialGroupLoading = true;
  258. getAllMaterialGroup({}).then(response => {
  259. this.materialGroupList = response.data
  260. console.log(this.materialGroupList)
  261. this.materialGroupLoading = false;
  262. });
  263. },
  264. getMaterialList() {
  265. this.tableLoading = true;
  266. listMaterial(this.queryParams).then(response => {
  267. this.tableData = response.rows;
  268. this.total = response.total;
  269. this.tableLoading = false;
  270. });
  271. },
  272. moveMaterial(index, type) {
  273. if (type == 'up') {
  274. const tempOption = this.value[index - 1]
  275. this.$set(this.value, index - 1, this.value[index])
  276. this.$set(this.value, index, tempOption)
  277. }
  278. if (type == 'down') {
  279. const tempOption = this.value[index + 1]
  280. this.$set(this.value, index + 1, this.value[index])
  281. this.$set(this.value, index, tempOption)
  282. }
  283. },
  284. zoomMaterial(index) {
  285. this.dialogVisible = true
  286. this.url = this.value[index]
  287. },
  288. deleteMaterial(index) {
  289. const that = this
  290. this.$confirm('是否确认删除?', '提示', {
  291. confirmButtonText: '确定',
  292. cancelButtonText: '取消',
  293. type: 'warning'
  294. }).then(function() {
  295. that.value.splice(index, 1)
  296. that.urls = []
  297. })
  298. },
  299. toSeleteMaterial() {
  300. this.listDialogVisible = true
  301. this.getAllMaterialGroup()
  302. this.getMaterialList();
  303. },
  304. materialDel(item) {
  305. const that = this
  306. this.$confirm('是否确认删除该素材?', '提示', {
  307. confirmButtonText: '确定',
  308. cancelButtonText: '取消',
  309. type: 'warning'
  310. }).then(function() {
  311. delMaterial(item.id)
  312. .then(function() {
  313. that.queryParams.pageNum=0;
  314. that.getMaterialList();
  315. })
  316. })
  317. },
  318. handleProgress(event, file, fileList) {
  319. },
  320. handleSuccess(response, file, fileList) {
  321. const that = this
  322. addMaterial({
  323. groupId: this.queryParams.groupId,
  324. fileName: file.name,
  325. url: response.url,
  326. data:response.data
  327. }).then(() => {
  328. this.resultNumber++
  329. if (fileList.length === this.resultNumber) {
  330. that.getMaterialList()
  331. this.resultNumber = 0
  332. }
  333. })
  334. },
  335. beforeUpload(file) {
  336. const isPic =
  337. file.type === 'image/jpeg' ||
  338. file.type === 'image/png' ||
  339. file.type === 'image/gif' ||
  340. file.type === 'image/jpg'
  341. const isLt2M = file.size / 1024 / 1024 < 2
  342. if (!isPic) {
  343. this.$message.error('上传图片只能是 JPG、JPEG、PNG、GIF 格式!')
  344. return false
  345. }
  346. if (!isLt2M) {
  347. this.$message.error('上传头像图片大小不能超过 2MB!')
  348. }
  349. return isPic && isLt2M
  350. },
  351. submit() {
  352. //console.log("qxj urls :"+JSON.stringify(this.urls));
  353. //console.log("qxj tableData:"+JSON.stringify(this.tableData));
  354. var data=this.tableData.find(item => item.url == this.urls) || {};
  355. this.$emit('pickImageData', data);
  356. this.listDialogVisible = false;
  357. this.urls=[];
  358. }
  359. }
  360. }
  361. </script>
  362. <style rel="stylesheet/scss" lang="scss" scoped>
  363. ::v-deep .el-icon-circle-close{
  364. color: red;
  365. }
  366. .material-name{
  367. padding: 8px 0px;
  368. }
  369. .col-do{
  370. text-align: center;
  371. }
  372. .button-do{
  373. padding: unset!important;
  374. font-size: 12px;
  375. }
  376. .group-list{
  377. display: flex;
  378. flex-direction:column;
  379. align-items: flex-start;
  380. }
  381. .group-item{
  382. margin: 5px;
  383. }
  384. </style>