index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <!--实验室安全制度-->
  2. <template>
  3. <div class="app-container safe-book" id="safe-book">
  4. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
  5. <el-form-item label="制度分类" prop="type">
  6. <el-select v-model="queryParams.type" placeholder="请选择制度分类" clearable size="small">
  7. <el-option
  8. v-for="item in safeType"
  9. :key="item.dictValue"
  10. :label="item.dictLabel"
  11. :value="item.dictValue"
  12. >
  13. </el-option>
  14. </el-select>
  15. </el-form-item>
  16. <el-form-item label="创建时间" prop="dateRange">
  17. <el-date-picker
  18. :clearable="false"
  19. v-model="dateRange"
  20. size="small"
  21. style="width: 240px"
  22. value-format="yyyy-MM-dd"
  23. type="daterange"
  24. range-separator="-"
  25. start-placeholder="开始日期"
  26. end-placeholder="结束日期"
  27. ></el-date-picker>
  28. </el-form-item>
  29. <el-form-item label="制度标题" prop="name">
  30. <el-input
  31. v-model="queryParams.name"
  32. placeholder="请输入制度标题"
  33. clearable
  34. maxLength="30"
  35. size="small"
  36. />
  37. </el-form-item>
  38. <el-form-item style="float: right;">
  39. <el-button
  40. type="primary"
  41. plain
  42. icon="el-icon-plus"
  43. size="mini"
  44. @click="handleAdd"
  45. v-hasPermi="['laboratory:safe_book:add']"
  46. >新增</el-button>
  47. </el-form-item>
  48. <el-form-item>
  49. <p class="inquire-button-one" @click="handleQuery">查询</p>
  50. <p class="reset-button-one" @click="resetQuery">重置</p>
  51. </el-form-item>
  52. </el-form>
  53. <el-table v-loading="loading" border :data="safe_bookList" @selection-change="handleSelectionChange">
  54. <el-table-column label="序号" type="index" align="center" width="50"/>
  55. <el-table-column label="标题" align="left" prop="name" />
  56. <el-table-column label="分类" align="left" prop="type" width="180">
  57. <template slot-scope="scope">
  58. <p v-for="item in safeType" v-if="item.dictValue == scope.row.type">{{item.dictLabel}}</p>
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="创建时间" align="left" prop="createTime" width="280"/>
  62. <el-table-column label="查看次数" align="left" prop="scanCount" width="100"/>
  63. <el-table-column label="二维码" align="left" width="100">
  64. <template slot-scope="scope">
  65. <div @click="dialogQrCodeOn(scope.row.qrCodeUrl)">
  66. <vue-qr style="height:23px;width:23px;cursor:pointer;" :text="scope.row.qrCodeUrl" :size="200"></vue-qr>
  67. </div>
  68. </template>
  69. </el-table-column>
  70. <el-table-column label="操作" align="center" width="160" v-if="tableButtonType">
  71. <template slot-scope="scope">
  72. <div class="button-box">
  73. <p class="table-min-button"
  74. style="margin-right:10px;"
  75. @click="handleUpdate(scope.row)"
  76. v-hasPermiAnd="['laboratory:safe_book:edit','laboratory:safe_book:query']"
  77. >编辑</p>
  78. <p class="table-min-button"
  79. @click="handleDelete(scope.row)"
  80. v-hasPermi="['laboratory:safe_book:remove']"
  81. >删除</p>
  82. </div>
  83. </template>
  84. </el-table-column>
  85. </el-table>
  86. <pagination :page-sizes="[20, 30, 40, 50]"
  87. v-show="total>0"
  88. :total="total"
  89. :page.sync="queryParams.pageNum"
  90. :limit.sync="queryParams.pageSize"
  91. @pagination="getList"
  92. />
  93. <!-- 添加或修改实验室安全制度对话框 -->
  94. <el-dialog :title="title" class="safe-book-el-dialog" :visible.sync="open" width="1000px" append-to-body>
  95. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  96. <el-form-item label="标题" prop="name" style="width:498px;">
  97. <el-input v-model="form.name" placeholder="请输入标题" maxLength="50"/>
  98. </el-form-item>
  99. <el-form-item label="制度分类" prop="type">
  100. <el-select v-model="form.type" placeholder="请选择制度分类">
  101. <el-option
  102. v-for="item in safeType"
  103. :key="item.dictValue"
  104. :label="item.dictLabel"
  105. :value="item.dictValue"
  106. >
  107. </el-option>
  108. </el-select>
  109. </el-form-item>
  110. <el-form-item label="编号" prop="code" style="width:498px;">
  111. <el-input v-model="form.code" placeholder="请输入编号" maxLength="10"/>
  112. </el-form-item>
  113. <el-form-item label="上传PDF" prop="content" v-if="open" style="margin-bottom:0;">
  114. <!--<editor v-model="form.content" :min-height="192"/>-->
  115. <!--<wangEditor v-model="form.content" @change="change" :min-height="192"/>-->
  116. <!--<wangEditor :content="form.content" @change="change" :min-height="192"/>-->
  117. <el-upload
  118. class="pdf-up-data"
  119. :action="uploadImgUrl"
  120. :show-file-list="false"
  121. accept="pdf"
  122. :on-success="handleAvatarSuccess"
  123. :headers="headers"
  124. :before-upload="beforeAvatarUpload">
  125. <img v-if="form.content" src="@/assets/ZDimages/pdf.png" style="margin-top:6px;" class="avatar">
  126. <i style="line-height: 30px;width: 32px;text-align: center;border: 1px solid #999;border-radius: 4px;font-size: 10px;"
  127. v-if="!form.content" class="el-icon-plus avatar-uploader-icon"></i>
  128. </el-upload>
  129. </el-form-item>
  130. <div v-if="form.content" class="pdf-max-box">
  131. <pdf
  132. ref="pdf"
  133. :src="form.content"
  134. v-for="i in numPages"
  135. :key="i"
  136. :page="i"
  137. >
  138. </pdf>
  139. </div>
  140. <!--
  141. <el-form-item label="二维码地址" prop="qrCodeUrl">
  142. <el-input v-model="form.qrCodeUrl" placeholder="请输入二维码地址" />
  143. </el-form-item>
  144. <el-form-item label="查看次数" prop="scanCount">
  145. <el-input v-model="form.scanCount" placeholder="请输入查看次数" />
  146. </el-form-item>
  147. <el-form-item label="备注" prop="remark">
  148. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  149. </el-form-item>
  150. -->
  151. </el-form>
  152. <div slot="footer" class="dialog-footer">
  153. <el-button type="primary" @click="submitForm">确 定</el-button>
  154. <el-button @click="cancel">取 消</el-button>
  155. </div>
  156. </el-dialog>
  157. <!-- 二维码展示 -->
  158. <el-dialog title="二维码" class="qr-codeUrl-dialog" :visible.sync="dialogQrCodeType" width="300px" append-to-body>
  159. <vue-qr style="display: block;height:200px;width:200px;cursor:pointer;margin:0 auto;" :text="dialogQrCodeUrl" :size="200"></vue-qr>
  160. </el-dialog>
  161. </div>
  162. </template>
  163. <script>
  164. import { listSafe_book, getSafe_book, delSafe_book, addSafe_book, updateSafe_book } from "@/api/laboratory/safe_book";
  165. import { getToken } from "@/utils/auth";
  166. import pdf from 'vue-pdf'
  167. import vueQr from 'vue-qr'
  168. export default {
  169. components:{
  170. pdf,
  171. vueQr
  172. },
  173. name: "Safe_book",
  174. data() {
  175. return {
  176. tableButtonType:this.hasPermiDom(['laboratory:safe_book:edit','laboratory:safe_book:query','laboratory:safe_book:remove']),
  177. uploadImgUrl: this.uploadUrl(), // 上传的图片服务器地址
  178. headers: {
  179. Authorization: "Bearer " + getToken(),
  180. },
  181. // 遮罩层
  182. loading: true,
  183. // 选中数组
  184. ids: [],
  185. // 非单个禁用
  186. single: true,
  187. // 非多个禁用
  188. multiple: true,
  189. // 显示搜索条件
  190. showSearch: true,
  191. // 总条数
  192. total: 0,
  193. // 实验室安全制度表格数据
  194. safe_bookList: [],
  195. // 弹出层标题
  196. title: "",
  197. // 是否显示弹出层
  198. open: false,
  199. // 查询参数
  200. queryParams: {
  201. pageNum: 1,
  202. pageSize:20,
  203. type: null,
  204. name: null,
  205. code: null,
  206. content: null,
  207. qrCodeUrl: null,
  208. scanCount: null,
  209. userId: null,
  210. deptId: null,
  211. deptName: null,
  212. },
  213. // 表单参数
  214. form: {},
  215. // 表单校验
  216. rules: {
  217. name:[
  218. {required: true, message: '请输入标题', trigger: 'blur'},
  219. { required: true, message: "请输入标题", validator: this.spaceJudgment, trigger: "blur" }
  220. ],
  221. type:[
  222. {required: true, message: '请选择制度分类', trigger: 'blur'}
  223. ],
  224. code:[
  225. {required: true, message: '请输入编号', trigger: 'blur'}
  226. ],
  227. content:[
  228. {required: true, message: '请上传PDF', trigger: 'blur'}
  229. ],
  230. },
  231. safeType:[],
  232. // 日期范围
  233. dateRange: [],
  234. //pdf相关
  235. numPages: null, // pdf 总页数
  236. //二维码展示数据
  237. dialogQrCodeType:false,
  238. dialogQrCodeUrl:"",
  239. };
  240. },
  241. created() {
  242. this.getList();
  243. this.getDicts("safe_type").then(response => {
  244. this.safeType = response.data;
  245. });
  246. },
  247. methods: {
  248. dialogQrCodeOn(url){
  249. this.dialogQrCodeUrl = url;
  250. this.dialogQrCodeType = true;
  251. },
  252. //上传
  253. handleAvatarSuccess(res, file) {
  254. this.form.content = window.location.href.split('://')[0]+'://' +this.judgmentNetworkReturnAddress() + '/' + res.data.url;
  255. this.form.realcontent =res.data.url;
  256. this.getNumPages();
  257. this.$forceUpdate()
  258. },
  259. beforeAvatarUpload(file) {
  260. let type = false;
  261. console.log('file',file);
  262. if (file.type == 'application/pdf') {
  263. type = true;
  264. }else{
  265. this.$message.error('只能上传pdf格式文件');
  266. type = false;
  267. }
  268. return type;
  269. },
  270. change(val) {
  271. this.$set(this.form,'content',val);
  272. // this.form.content = val;
  273. console.log(val)
  274. },
  275. /** 查询实验室安全制度列表 */
  276. getList() {
  277. this.loading = true;
  278. if(this.dateRange&&this.dateRange.length>0)
  279. {
  280. this.queryParams.beginTime=this.dateRange[0]
  281. this.queryParams.endTime=this.dateRange[1]
  282. }
  283. else
  284. {
  285. this.queryParams.beginTime=null;
  286. this.queryParams.endTime=null
  287. }
  288. listSafe_book(this.queryParams).then( response => {
  289. this.safe_bookList = response.rows;
  290. this.total = response.total;
  291. this.loading = false;
  292. });
  293. },
  294. // 取消按钮
  295. cancel() {
  296. this.open = false;
  297. this.reset();
  298. },
  299. // 表单重置
  300. reset() {
  301. this.form = {
  302. id: null,
  303. type: null,
  304. name: null,
  305. code: null,
  306. content: null,
  307. realcontent: null,
  308. qrCodeUrl: null,
  309. scanCount: null,
  310. userId: null,
  311. createBy: null,
  312. updateBy: null,
  313. deptId: null,
  314. deptName: null,
  315. createTime: null,
  316. updateTime: null,
  317. remark: null
  318. };
  319. this.resetForm("form");
  320. },
  321. /** 搜索按钮操作 */
  322. handleQuery() {
  323. this.queryParams.pageNum = 1;
  324. this.getList();
  325. },
  326. /** 重置按钮操作 */
  327. resetQuery() {
  328. this.resetForm("queryForm");
  329. this.dateRange=[];
  330. this.handleQuery();
  331. },
  332. // 多选框选中数据
  333. handleSelectionChange(selection) {
  334. this.ids = selection.map(item => item.id)
  335. this.single = selection.length!==1
  336. this.multiple = !selection.length
  337. },
  338. /** 新增按钮操作 */
  339. handleAdd() {
  340. this.reset();
  341. this.open = true;
  342. this.title = "添加实验室安全制度";
  343. },
  344. /** 修改按钮操作 */
  345. handleUpdate(row) {
  346. this.reset();
  347. const id = row.id || this.ids
  348. getSafe_book(id).then( response => {
  349. this.form = response.data;
  350. this.form.content = window.location.href.split('://')[0]+'://' + response.data.content.split('://')[1];
  351. this.getNumPages();
  352. this.open = true;
  353. this.title = "修改实验室安全制度";
  354. });
  355. },
  356. getNumPages() {
  357. let loadingTask = pdf.createLoadingTask(this.form.content)
  358. loadingTask.promise.then(pdf => {
  359. this.numPages = pdf.numPages
  360. }).catch(err => {
  361. console.error('pdf 加载失败', err);
  362. })
  363. },
  364. /** 提交按钮 */
  365. submitForm() {
  366. this.$refs["form"].validate(valid => {
  367. this.form.content=this.form.realcontent;
  368. if (valid) {
  369. // this.form.content = escape(this.form.content);
  370. if (this.form.id != null) {
  371. updateSafe_book(this.form).then( response => {
  372. this.msgSuccess("修改成功");
  373. this.open = false;
  374. this.reset();
  375. this.getList();
  376. });
  377. } else {
  378. addSafe_book(this.form).then( response => {
  379. this.msgSuccess("新增成功");
  380. this.open = false;
  381. this.reset();
  382. this.getList();
  383. });
  384. }
  385. }
  386. });
  387. },
  388. /** 删除按钮操作 */
  389. handleDelete(row) {
  390. const ids = row.id || this.ids;
  391. this.$confirm('是否确认删除该安全制度?', "警告", {
  392. confirmButtonText: "确定",
  393. cancelButtonText: "取消",
  394. type: "warning"
  395. }).then(function() {
  396. return delSafe_book(ids);
  397. }).then(() => {
  398. this.getList();
  399. this.msgSuccess("删除成功");
  400. }).catch(() => {});
  401. },
  402. /** 导出按钮操作 */
  403. handleExport() {
  404. this.download('laboratory/safe_book/export', {
  405. ...this.queryParams
  406. }, `laboratory_safe_book.xlsx`)
  407. }
  408. }
  409. };
  410. </script>
  411. <style scoped lang="scss">
  412. #safe-book {
  413. display: flex !important;
  414. flex-direction: column;
  415. box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
  416. padding:20px!important;
  417. .button-box{
  418. margin:0 auto;
  419. width:190px;
  420. display: flex;
  421. }
  422. }
  423. </style>