uploadsketch.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <template>
  2. <view style="position: relative;">
  3. <!-- 胶囊 -->
  4. <mvBar :mysNavConfig="mysNavConfig"></mvBar>
  5. <view style="margin-top: 160rpx;"></view>
  6. <view @click="toRecord()" style="margin-bottom:20rpx">
  7. <view style="display: flex;justify-content: center;">
  8. <image style="height: 60rpx;width: 60rpx;" src="../../static/img/icon-clock.png"></image>
  9. </view>
  10. <view style="display: flex;justify-content: center;">
  11. <p style="font-size: 32rpx;">查看修改/反馈记录</p>
  12. </view>
  13. </view>
  14. <view style="display: flex;justify-content: center;">
  15. <radio-group @change="chan">
  16. <label v-for="item in radioGroup" :key="item">
  17. <view style="display: inline;margin: 0 20rpx">
  18. <radio :value="item" :checked="item==activeRadio" color="#fdd544" />{{item}}
  19. </view>
  20. </label>
  21. </radio-group>
  22. </view>
  23. <view style="margin: 30rpx;display: flex;justify-content: center;" v-if="activeRadio == '图片'">
  24. <htz-image-upload :max="18" mediaType="image" name="file" :chooseNum="9" v-model="imageData"
  25. @chooseSuccess="ceshiChooseSuccess1">
  26. </htz-image-upload>
  27. </view>
  28. <view style="margin: 30rpx;display: flex;justify-content: center;" v-if="activeRadio == '视频'">
  29. <htz-image-upload :max="1" mediaType="video" name="file" :chooseNum="1" v-model="videoData"
  30. @chooseSuccess="ceshiChooseSuccess2">
  31. </htz-image-upload>
  32. </view>
  33. <uni-easyinput type="text" :inputBorder="false" v-model="title" placeholder="在此填写让人眼前一亮的标题吧">
  34. </uni-easyinput>
  35. <!-- 多行输入框 -->
  36. <view style="padding: 40rpx 30rpx 150rpx;font-size: 32rpx">
  37. <textarea v-model="text" maxlength="2000" auto-height="true" placeholder="添加正文" />
  38. </view>
  39. <view class="signup">
  40. <button type="default" class="but1" :loading="loading" :class="{'on':item.title == '1',}" @click="submit()">
  41. 提交初稿</button>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. import mvBar from "@/components/mys_navBar/mysNavBar";
  47. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue';
  48. import getPolicyEncode from '@/components/obs/getPolicy.js';
  49. import getSignature from '@/components/obs/GetSignature.js';
  50. export default {
  51. components: {
  52. mvBar,
  53. htzImageUpload,
  54. },
  55. data() {
  56. return {
  57. taskId: "",
  58. title: "",
  59. text: "",
  60. sketchStatus: "",
  61. activeRadio: '图片', //存的是选中的value值
  62. radioGroup: ['图片', '视频'],
  63. videoData: [],
  64. imageData: [],
  65. mysNavConfig: {
  66. /* 开启单页显示首页图标 */
  67. isHome: true,
  68. /* 固定导航 */
  69. navFixed: true,
  70. /* 标题 (屏幕中心居中 两边图标中心居中使用slot center1) */
  71. navTitle: {
  72. text: "上传初稿",
  73. color: "",
  74. fontSize: "32rpx", // px upx rpx
  75. fontWeight: "normal", // 100 - 700
  76. },
  77. btnType: "type2",
  78. onLeftClick: '',
  79. /* type2 按钮 */
  80. type2Config: {
  81. // 左图标
  82. leftPath: "/static/img/png2.png",
  83. // 右图标
  84. rightPath: "/static/img/png4.png",
  85. // 圆角
  86. radius: "40rpx",
  87. },
  88. },
  89. }
  90. },
  91. onLoad(options) {
  92. let data = options.textObj.replace(/""/g, "");
  93. data = JSON.parse(decodeURIComponent(data))
  94. this.taskId = data.taskId
  95. this.sketchStatus = data.sketchStatus
  96. this.getSketch()
  97. },
  98. methods: {
  99. chan(e) {
  100. this.activeRadio = e.detail.value;
  101. console.log(this.activeRadio);
  102. },
  103. getSketch() {
  104. this.$https.get('/youngee/c/t/g/get-unsubmit-task-sketch' +
  105. "?" +
  106. "task_id" +
  107. "=" +
  108. this.taskId)
  109. .then(res => {
  110. console.log(res)
  111. if (res.data.data != null) {
  112. this.title = res.data.data.title
  113. this.text = res.data.data.content
  114. if (res.data.data.type == 1) { // 图片
  115. this.activeRadio = '图片'
  116. for (var j = 0; j < res.data.data.Photo.length; j++) {
  117. this.imageData.push(res.data.data.Photo[j].photo_url)
  118. }
  119. } else if (res.data.data.type == 2) { //视频
  120. this.activeRadio = '视频'
  121. for (var j = 0; j < res.data.data.Photo.length; j++) {
  122. this.videoData.push(res.data.data.Photo[j].photo_url)
  123. }
  124. }
  125. }
  126. })
  127. },
  128. toRecord() {
  129. var data = {
  130. taskId: this.taskId,
  131. };
  132. data = JSON.stringify(data)
  133. uni.navigateTo({
  134. url: '/pages/workspace/sketchrecord?textObj=' + encodeURIComponent(data)
  135. });
  136. },
  137. submit() {
  138. // 检验标题和内容是否为空
  139. let type = 0
  140. let photourl = []
  141. if (this.activeRadio == '图片') { // 图片
  142. type = 1
  143. photourl = this.imageData
  144. } else {
  145. type = 2
  146. photourl = this.videoData
  147. }
  148. if (this.title == '') {
  149. uni.showToast({
  150. title: "请填写初稿标题",
  151. icon: 'none'
  152. })
  153. return
  154. }
  155. if (this.text == '') {
  156. uni.showToast({
  157. title: "请填写初稿内容",
  158. icon: 'none'
  159. })
  160. return
  161. }
  162. if (photourl.length == 0) {
  163. uni.showToast({
  164. title: "请上传初稿图片或视频",
  165. icon: 'none'
  166. })
  167. return
  168. }
  169. console.log("photourl:", photourl)
  170. this.$https.post('/youngee/c/t/p/add-task-sketch', {
  171. task_id: this.taskId,
  172. title: this.title,
  173. content: this.text,
  174. type: type,
  175. photo_url: photourl.toString()
  176. })
  177. .then(res => {
  178. console.log(res)
  179. uni.navigateBack()
  180. })
  181. },
  182. ceshiChooseSuccess1(tempFilePaths, e) { //选择图片返回
  183. console.log('ceshiChooseSuccess', tempFilePaths, e);
  184. /****************
  185. 以下代码是自定义上传逻辑,仅供参考
  186. ***************/
  187. this.imgUpload1(tempFilePaths, e);
  188. /*******************************/
  189. console.log("imgdata" + this.imageData)
  190. },
  191. imgUpload1(tempFilePaths, e) {
  192. let that = this
  193. console.log('imgUpload', tempFilePaths)
  194. let config = {
  195. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  196. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  197. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  198. };
  199. for (let i = 0; i < tempFilePaths.length; ++i) {
  200. if (e == 0) {
  201. this.store = 'talent_upload/' + this.guid() + '.png'
  202. } else if (e == 1) {
  203. this.store = 'talent_upload/' + this.guid() + '.mp4'
  204. }
  205. let fileName = this.store; //指定上传到OBS桶中的对象名
  206. let OBSPolicy = { //设定policy内容
  207. "expiration": "2089-12-31T12:00:00.000Z",
  208. "conditions": [{
  209. "bucket": "horastar"
  210. }, //Bucket name
  211. // {"bucket": "goin"},
  212. {
  213. 'key': fileName
  214. }
  215. ]
  216. }
  217. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  218. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  219. uni.uploadFile({
  220. //url: config.EndPoint,
  221. url: config.EndPoint,
  222. filePath: tempFilePaths[i],
  223. name: 'file',
  224. formData: {
  225. 'AccessKeyID': config.AccessKeyId,
  226. 'policy': policyEncoded,
  227. 'signature': signature,
  228. 'key': fileName,
  229. },
  230. success: function(res) {
  231. console.log(res.statusCode); //打印响应状态码
  232. if (res.statusCode == '204') {
  233. that.imageData.push(config.EndPoint + '/' + fileName);
  234. console.log('上传图片成功', res)
  235. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  236. console.log(obs_url)
  237. // that.formData.home_img = obs_url
  238. uni.showToast({
  239. title: '上传成功',
  240. icon: '成功'
  241. });
  242. } else {
  243. console.log('上传图片失败', res)
  244. uni.showToast({
  245. title: '上传失败',
  246. icon: '失败'
  247. });
  248. }
  249. },
  250. fail: function(e) {
  251. console.log(e);
  252. uni.showToast({
  253. title: '上传失败22222',
  254. icon: '失败'
  255. });
  256. }
  257. })
  258. }
  259. },
  260. ceshiChooseSuccess2(tempFilePaths, e) { //选择视频返回
  261. console.log('ceshiChooseSuccess', tempFilePaths, e);
  262. if (e == 0) {
  263. this.store = 'talent_upload/' + this.guid() + '.png'
  264. } else if (e == 1) {
  265. this.store = 'talent_upload/' + this.guid() + '.mp4'
  266. }
  267. /****************
  268. 以下代码是自定义上传逻辑,仅供参考
  269. ***************/
  270. this.imgUpload2(tempFilePaths);
  271. /*******************************/
  272. console.log("videoData" + this.videoData)
  273. },
  274. imgUpload2(tempFilePaths) {
  275. let that = this
  276. console.log('videoUpload', tempFilePaths)
  277. let config = {
  278. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  279. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  280. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  281. };
  282. let fileName = this.store; //指定上传到OBS桶中的对象名
  283. // let fileName = "talent_upload/icon-arrow-right.png"
  284. let OBSPolicy = { //设定policy内容
  285. "expiration": "2089-12-31T12:00:00.000Z",
  286. "conditions": [{
  287. "bucket": "horastar"
  288. }, //Bucket name
  289. // {"bucket": "goin"},
  290. {
  291. 'key': fileName
  292. }
  293. ]
  294. }
  295. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  296. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  297. uni.uploadFile({
  298. //url: config.EndPoint,
  299. url: config.EndPoint,
  300. filePath: tempFilePaths[0],
  301. name: 'file',
  302. formData: {
  303. 'AccessKeyID': config.AccessKeyId,
  304. 'policy': policyEncoded,
  305. 'signature': signature,
  306. 'key': fileName,
  307. },
  308. success: function(res) {
  309. console.log(res.statusCode); //打印响应状态码
  310. if (res.statusCode == '204') {
  311. that.videoData.push(config.EndPoint + '/' + fileName);
  312. console.log('上传图片成功', res)
  313. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  314. console.log(obs_url)
  315. // that.formData.home_img = obs_url
  316. uni.showToast({
  317. title: '上传成功',
  318. icon: '成功'
  319. });
  320. } else {
  321. console.log('上传图片失败', res)
  322. uni.showToast({
  323. title: '上传失败',
  324. icon: '失败'
  325. });
  326. }
  327. },
  328. fail: function(e) {
  329. console.log(e);
  330. uni.showToast({
  331. title: '上传失败22222',
  332. icon: '失败'
  333. });
  334. }
  335. })
  336. },
  337. guid() {
  338. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  339. var r = Math.random() * 16 | 0,
  340. v = c == 'x' ? r : (r & 0x3 | 0x8);
  341. return v.toString(16);
  342. });
  343. },
  344. },
  345. }
  346. </script>
  347. <style lang="scss" scoped>
  348. .signup {
  349. box-shadow: 0rpx 5rpx 40rpx #ccc;
  350. width: 100%;
  351. position: fixed;
  352. bottom: 0rpx;
  353. display: flex;
  354. height: 90rpx;
  355. padding-top: 2%;
  356. background-color: #FFFFFF;
  357. z-index: 99;
  358. }
  359. .but1 {
  360. width: 60%;
  361. background-color: #f2d22d;
  362. border-radius: 20rpx;
  363. font-size: 36rpx;
  364. line-height: 200%;
  365. letter-spacing: 10rpx;
  366. font-weight: 500;
  367. height: 80%;
  368. &.on {
  369. background-color: #C0C0C0;
  370. }
  371. }
  372. </style>